12 years, 11 months ago.

how to syncronize two mbed?

i am making a system in which the output of one mbed is the input of other mbed. the first mbed sends some bits i.e 1010 on its output in ms but the problem is the other mbed is unable to figure out what was sent on its input it takes it 1000.

4 Answers

12 years, 11 months ago.

We would need to see your code to figure out what is going wrong, but probably the easiest solution is simply using the UARTs to connect the two mbeds (Or I2C/SPI, although without a specific reason to choose them I would simply go for the UARTs).

12 years, 10 months ago.

I am also attempting to syncronize two mbeds to demonstrate modulation and demodulation techniques, could you provide sample code demonstrating how you would use the UARTs to syncronize the two boards?

If I understood it correctly here the question was more how to syncronize (so send) data between two mbeds. You want to synchronise two mbeds so they start doing something at the same time? Then you can simply make a digitalOut that goes high at a certain time, and depending on the requirements the other mbed either uses digitalIn and polls that, or uses an interruptIn.

posted by Erik - 06 Nov 2012

i am sending data from one mbed to other mbed in 4ms. like four bits 1010. this digital output is sent to other mbed digitalin. as it gets the first bit it starts working. but it takes it 1000 or some time 1001 its the clock difference error. :(

posted by sanwal muneer 06 Nov 2012
12 years, 10 months ago.

its the reception side code.

  1. include "mbed.h"

DigitalOut m1(LED1); DigitalOut m2(LED2); DigitalOut m3(LED3); DigitalOut m4(LED4); DigitalIn t(p6); Timer time1; int a[4]={0,0,0,0}; int i=0; int j=0; int main() { x: m1=a[0]; m2=a[1]; m3=a[2]; m4=a[3];

while(1){ if(t==1) { time1.start(); while(1) { if (time1.read_ms()<=5) { if (time1.read_ms()<=1 && j==0) {a[i]=t; i++; j=1;} else if (time1.read_ms()>1 && time1.read_ms()<=2 && j==1) {a[i]=t; i++; j=2;} else if (time1.read_ms()>2 && time1.read_ms()<=3 && j==2) {a[i]=t; i++; j=3;} else if (time1.read_ms()>3 && time1.read_ms()<=5 && j==3) {a[i]=t; i++; j=4;} else if (time1.read_ms()>5 && j==4) { goto x; }

} }

} } }

12 years, 10 months ago.

Use <<code>> and <</code>> around your code to make it better readable.

But for you my comment still stands, the easiest way to do it is simply using the Serial library and then the UART pins. The problem most likely now is that you are sampling at the edges, and not in the center of a bit. But while you could fix that, the UART is simply a better solution.