11 years, 4 months ago.

How to send a buffer of data(having more than 1 char) over serial in one go

Hi

I am working on my project with serial ports of mbed and want to know is there any way i can send a complete data buffer(e.g ABCDEF.....) over the serial port. i want to send data to xbee and then use it for processing.

can anyone help me about it is there any way or i just have to send the data character by character (looping)??

Thank you

2 Answers

11 years, 4 months ago.

Hi,

To send a buffer over the serial port you can use the printf function, you can find out how to implement it here

Here's some example code for printing a buffer over a serial link.

serial xbee(p13,p14);

char buff[] = "abcdefg";
xbee.printf("%s",buff);

For more information on printf go here

Accepted Answer

Thanks Tristan Actually i have tried this but sumhow that doesn't work. the sending side is ok Xbee TX but receiver keeps waiting don't know what happens i am using xbee s1 from digi...can you help ?

posted by Syed Aftab 30 Jul 2013

Have you checked that both xbee's are configured the same?

Try using the hello world programs on here to see if that fixes your problem.

posted by Tristan Hughes 30 Jul 2013
Syed Aftab
poster
11 years, 4 months ago.

Thank you again Tristan

but unfortunately the echo program that you just send me also don't work with me. :( my Transmitter is working fine but receiver is not getting anything :( don't know what is the problem. can you help me

attached is the code of both TX and RX

..........TX.................

  1. include "mbed.h" Serial xbee1(p9, p10); DigitalOut rst1(p11);

DigitalOut myled1(LED1); DigitalOut myled2(LED2);

Serial pc(USBTX, USBRX);

int main() {

pc.baud(9600); xbee1.baud(9600);

char a,b; char buff[]="1111 1234 mynameisaftabmynameisaftabmynameisaftab";

while(1)

{

rst1 = 0;

wait_ms(1); rst1 = 1;

int i=0; if(xbee1.writeable()) { while(buff[i]!='\0') { xbee1.putc(buff[i]); pc.putc(buff[i]); i++; myled1=0; wait(.1); myled1=1; } }

} }

.......RX..............

  1. include "mbed.h" Serial xbee1(p9, p10); DigitalOut rst1(p11);

DigitalOut myled1(LED1); DigitalOut myled2(LED2);

Serial pc(USBTX, USBRX);

int main() {

pc.baud(9600); xbee1.baud(9600); int i; char a,b; char data[100];

reset the xbees (at least 200ns)

while(1)

{ i=0; rst1 = 0; wait_ms(1); rst1 = 1;

if(xbee1.readable()) { a=xbee1.getc(); while(a!='\0') { data[i]=a; pc.putc(data[i]); i++; a=xbee1.getc(); myled1=0; wait(.1); myled1=1; } }

} }

can anyone help me :(