Hi!
I have written a program for PIC that responds to a Modbus request. It works fine!
But I'm not going to use the PIC, instead I'm using a ATmega324P, I use the same C-code with only the minor changes of
registers and settings ofcourse. The program works for ATMega324P. But the receiving side does not accept the data.
I could not understand why, I used a display to debug. I set up both the PIC and ATmega circuit with a display to verify
that both the MCU's are receiving the same data. They do!
Then I used a oscilloscope on the TX pin to verify that they were also transmitting the same data. And they do!
But the difference is that the ATmega324P is sending the data a little bit slower than the PIC.
And I cannot figure out why. I was thinking maybe the ATMega was set to send 9 bit's, but it's not.
Both MCU's are set to 9600bps with 4MHz crystal oscillator. The ATMega is set to "Full Swing oscillator, fast rising"
I have tried a different setting, same result.
setting for ATMega324P
UBBR0=0x19 //25 for 4MHz
U2X0=0;
RXEN0=1;
TXEN0=1;
UCSZ02=0;
USBD0=1;
UCSZ00=3;
this is a picture of the data on the TX pin. It does seem like the ATmega is sending in 9-bit format, or sending an extra bit.
since it's approx 1ms longer. This data is 13 bytes big, so 13bit's take approx 0.00135417s or 1.3ms to send in 9600bps.
But it shouldn't, UCSZ00=3; is 8-bit format right?
I have also tried to change the value of UBBR0 to make the MCU send data faster, but the it cannot receive data correctly...