Serial terminal printing Weird Characters

Hi, I’m using lpc1768 board and I’m trying to develop board to board serial communication system. I’m referring BufferedSerial (https://os.mbed.com/docs/mbed-os/v6.10/apis/serial-uart-apis.html) library for this.
When I write something to serial, It prints weird characters. Can you help me to solve this issue?

(my code as follows)

 char m_buffer[30];
 void sendChar(char *charCharacter)
   {
            serialPort.write(m_buffer, *charCharacter);
   }

  void sendString(char str[])
 {

        int i=0;

        while(str[i] != 0x00)

        {

            sendChar(&str[i]);

            i++;

            //printf("%c", str[i]);

        }

    }
 int main() { 
 char str[] = {"hello World"};
 sendString(str);
 }

Hello,

That usually occurs when both sides not use same baud rate.

But your sendChar function seems be strange.

serialPort.write(m_buffer, *charCharacter);

Definition of write is - ssize_t write (const void *buffer, size_t length) override
So from my point of view, you must to use it like this

serialPort.write(&charCharacter, 1);
//or
serialPort.write(&charCharacter, sizeof(char));

Or write it together

 int main() { 
    char str[] = {"hello World"};
    serialPort.write(&str, strlen(str));
 }

BR, Jan

1 Like

Where I can find more sample codes? Because I’m a beginner.

In general there is a page with Code | Mbed and in the Mbed documentation you will find basic examples for all APIs. Also the forum is full of informations from old topics.
Anyway if you will stuck somewhere just ask here and someone will help you, if it will be possible.

BR, Jan

1 Like

thank you JohnnyK