Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 months ago.
UART baud rate
Hello guys,
Is it possible to have one Serial port working on 9600 baud rate, a different Serial port on 250000 bps and work together?
I am receiving 512 integers from UART2 (receiving them using XBee module), which has to work on 9600bps. I want to store these values in an array and then transmit them through UART3 but using a baud rate of 250000bps.
Any ideas of how to do that?
Thanks for any help
2 Answers
10 years, 3 months ago.
You can declare two Serial ports and by selecting the right pins make sure they are on different UARTs. Easiest way to transfer data between them is probably a ringbuffer. You can either use interrups or use polling on the receiver serial port to fill the buffer and use another interrupt or poll to check if there is data waiting to be transmitted. The ringbuffer may be overkill in this case since the transmitter side is much faster than the receiver and you probably dont have flowcontrol on the tx port.
10 years, 3 months ago.
Since your transmit is far faster than your receive and assuming you don't have any transmit flow control then something like this should do it:
#include <mbed.h> #include "RawSerial.h" RawSerial inputPort(port1_tx,port1_rxPin); RawSerial outputPort(port2_txPin,port2_rxPin); void dataArrived(void) { while (inputPort.readable()) { outputPort.putc(inputPort.getc()); } } main() { inputPort.baud(9600); outputPort.baud(250000); inputPort.attach(&dataArrived); while (1) { // twiddle your thumbs... } }