8 years ago.

trash data on serial connection

Hello! I have this serial connection between the nucleo and PIC. I am using the pins (PA_9,PA_10) for the RX,TX of the nucleo connected to the rx,tx of the PIC. The PIC will be sending a string message to the nucleo, but the data displayed in the serial monitor is just trash. What may be the cause of the problem?

I used the basic program for reading if there is an available data in the serial port.

#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
Serial device(PA_9, PA_10);  // tx, rx
 
int main() {

    while(1) {
      
        if(device.readable()) {
            pc.putc(device.getc());
        }
    }
}

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

2 Answers

8 years ago.

do you connect the tx of one microprocessor to the rx of the other ? Do you define the same speed, parity ? Do you care for a common ground ? Are both microprocessor with the same logic level (3,3V) ?

Yes. All of the things that you have mentioned are already considered but still I cannot get a good output.

posted by Jas Y 28 Apr 2016

Another thing is I think I read that on the newer PIC devices there are control bits to invert the polarity of the serial signals. The TX line should idle high when not transmitting.

posted by Oliver Broad 28 Apr 2016
8 years ago.

I think it is most likely to be a speed mismatch. If you've confirmed that the settings are right then look at the PIC clock configuration.

Just to clarify that, I would expect the Nucleo to go to 9600 baud if it isn't set. The PIC will need to be set to 9600 baud to match. Also with the PIC there is no standard clock frequency so it is important to ensure the compiler option is set correctly.

posted by Oliver Broad 25 Apr 2016

It has the same baud and the clock frequency is set. Do you know any other way to listen to the incoming data from the PIC except from the sample code of the nucleo? Thanks.

posted by Jas Y 28 Apr 2016

Use a test program to send a known bit pattern repeatedly like 0xF0 which should give you a 960Hz square wave, 5 bits low 5 bits high.

It should be possible to measure the frequency.

posted by Oliver Broad 28 Apr 2016