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.
6 years, 6 months ago.
Nucleo - STM32F410RB not reading from serial port
I have a 3DR radio telemetry setup with which I am trying to establish two way communications between a laptop and the Nucleo board. The board functions fine while transmitting data but it is just not reading from the radio. The radio receives the data, and also on the laptop side, the radio is successfully transmitting data.
STM32F410RB code
#include "mbed.h" #define TX_PIN PB_6 #define RX_PIN PA_10 Serial pc(USBTX, USBRX); Serial pc2(TX_PIN, RX_PIN); DigitalOut myled(LED1); char recvdChar = 'a'; void recvdData(){ recvdChar = pc2.getc(); } int main() { pc.baud(57600); pc2.baud(57600); pc2.abort_write(); //pc.printf("STARTING\n"); myled = 1; wait(1); myled = !myled; pc2.attach(&recvdData, Serial::RxIrq); while(1) { pc.printf("%c\n", recvdChar); wait(0.5); } }
Laptop code
import serial import time board = serial.Serial(port = '/dev/tty.usbserial-DN02136Z', baudrate = 57600 , timeout = 3) time.sleep(3) while(1): board.write("w")
Assigned to
6 years, 6 months ago.This means that the question has been accepted and is being worked on.
You probably should declare the variable recvdChar as 'volatile' since it is updated in an interrupt. The compiler does not understand that and might optimise out re-checking the new value before printing it in your main loop.
posted by Wim Huiskamp 05 Dec 2017