Help regarding strange uart0 behavior

Hi all,

I have built a RPi hat with some temperature sensors on it which communicates with the RPi via uart0. And I get some weird behavior from the serialport.
I'm using an ATMEGA328P-AU clocked at 8 MHz. This causes me to having to double the baudrate in the Serial.begin() function compared to what the actual rate will be. Why is this and how can I change it? The fuses are set correctly.

In my main loop, I listen for incoming serial data as the first thing in each loop. I listen by if(Serial.available() > 0). For some reason I seem to get serialdata when I should not.
I am debugging the hat unconnected to the RPi, so there is no chance of the Pi being the issue.

I am entering HandleSerialComms() even when no serial data is sent. Is the an obvious reason for this that I am not seeing?

I am also not not able to read an ascii character correct most times I try to send a character.
Output is written just fine, so I don't think that timing is the issue either?

SYSTEM_STATE is just a state variable that can represent one of several states. 0= STOPPED.

void loop() {
  if(Serial.available()>0)
  {
    HandleSerialComms();
  }
  if(millis() - lastTime >= updateInterval)
  {
    lastTime = millis();
    
    if( SYSTEM_STATE )
    {
      runMeasurements();  
    }
    
  }
}

zenseidk:
I'm using an ATMEGA328P-AU clocked at 8 MHz. This causes me to having to double the baudrate in the Serial.begin() function compared to what the actual rate will be

Have you configured the Arduino IDE for an 8Mhz device ?

I have not. How do I do this?

I found that the serial bug may actually be a hardware issue. Probably a bad soldering somewhere.

I have a second board that does not give me the same problem.

All right, both problems solved. Thank :slight_smile: