Reputation: 11
This is my first time posting to this forum and I hope you can help me out.
For my research project, I need to implement a Petri Net executioner in C to use all the subsystems of a micro controller. I have been using Atmel Studio 6.2 to simulate the results of my net.
I am running into a lot of problems with the UART system in particular.
void transmiteUART0(unsigned char data)
{
//Wait until the Transmitter is ready
while ( (UCSR0A & (1 << UDRE0))==0 );
//Get that data outta here!
UDR0 = data;
}
This is my function for the transmitting the UART system. But when I try assign the data to UDR0, it won't assign because the UDRE0 bit is still set in UCSR0A register and the simulator won't let me turn this bit off.
Any solutions? I apologize if this is a fairly basic questions but I tried all different types of solutions and emulated tutorials and I can't seem to figure out why it isn't working.
Upvotes: 1
Views: 485
Reputation: 363
This answer assumes that you are dealing with an Arduino Uno Microcontroller (ATmega328P).
I find that the following code is basically the same as your code, indicating that you should look elsewhere for your problem (hardware issue, circuit translation issue, short-circuit, cable problem, connector problem, etc):
void USART_Transmit(unsigned char data)
{
/* Wait for empty transmit buffer */
while (!(UCSRnA & (1<<UDREn)))
;
/* Put data into buffer, sends the data */
UDRn = data;
}
The above code was copied from:
Arduino Uno microcontroller datasheet
ATmega328P (Automobile == Automotive temperature range: –40°C to +125°C)
Page 150 of 294
https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf
Upvotes: 0