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.
8 years, 1 month ago.
Serial loopback Nucleo-F446RE
Hello, i am trying to create a loopback using the Serial (MODSERIAL, RawSerial, anything goes really) library and just cant get it to work. The program must get a value from a matrix keyboard, print it on a LCD, send it to the UART on the nucleo board, read it from the same UART and print it again on the LCD. here is an idea of what im trying to do:
Practica 6
//Define Uart to use Serial Uart1(D1, D0); // tx, rx //Variable to store data char Data[2]; int main() { int * Index; lcd.printf("1"); Index = teclado(); //Data[0] is the value obtained by the keyboard, char Data[0] = Simbolos[Index[0]][Index[1]]; Uart1.baud(9600); while(Uart1.writeable() != 1){} Uart1.putc(Data[0]); lcd.locate(0,1); Data[1] = Uart1.getc(); lcd.printf("%c",Data[1]); }
I have omited the way the value from the keyboard is obtained and lcd declaration, they are both working just fine. If it helps, whenever i use Uart1.writeable(); i get a 1, ALWAYS, and when i use Uart1.readable(); i get a 0, ALWAYS. I have seen some codes that work, but they use a pc conection, and i need to do this using ONLY my nucleo board. Also, when debugging i could see that the problem was ALWAYS with Uart1.getc(); it freezes everything, as if waiting for an imput or something. please please please help
1 Answer
8 years, 1 month ago.
Try the following. What do you see ? Report your results. Change the value of Data[0] to 'b' and then again to 'c' to see the results.
If you wish to see what you transmit then TX & RX pins must be shorted so that the OUTPUT from the UART (TX) is mated with the INPUT to the UART (RX).
Also review this thread for an improved solution to using the serial ports:
https://developer.mbed.org/questions/75751/Using-the-UART-on-DISCO-L476VG-board/#answer11399
https://developer.mbed.org/users/sam_grove/code/BufferedSerial/
Try a simple write to the UART with a few char string like "Hello" -> be sure that TX & RX are shorted for your UART pins -> check the receive buffer after this code run. You should be able to see what you transmitted inside your receive buffer. Keep in mind that the buffer depth is limited so only test with a few characters at a time. Otherwise you will face a buffer overrun (where the buffer is unable to hold all received data due to limited space inside the UART). Often hardware flow control is used to fix such issues. This is when the receiver will report to the transmitter - stop because my buffer is about to be filled ! Then the transmitter waits till the receiver digests the information that was received and then allows the transmitter to continue to send more data.
//Define Uart to use Serial Uart1(D1, D0); // tx, rx //Variable to store data char Data[2]; int main() { int * Index; lcd.printf("1"); Index = teclado(); //Data[0] is the value obtained by the keyboard, char //Data[0] = Simbolos[Index[0]][Index[1]]; Data[0] = 'a'; // UART will transmit the character 'a' and the UART receiver will receive 'a' if TX & RX pins are shorted Uart1.baud(9600); while(Uart1.writeable() != 1){} Uart1.putc(Data[0]); //lcd.locate(0,1); // most likely taking too much time so UART receive cannot capture the transmitted data Data[1] = Uart1.getc(); lcd.locate(0,1); lcd.printf("%c",Data[1]); }