Porting Arduino pro mini code to esp32 (playing with serial communication)
Posted: Thu Oct 22, 2020 4:13 pm
Hello, for my project I need to communicate with a RF module (R9M from FrSky) with a protocol called PXX or PCM. After some time I understood how it worked and also found a library that could be used. Saddly this library is made for Arduino pro mini and calls registers and buffers in two functions... The rest is fine.
Here is the code that is causing me problems and that I would like to port to esp32
if anyone could help me I could really appreciate it
Here is the code that is causing me problems and that I would like to port to esp32
Code: Select all
void USART_Init(long baud)
{
int _baud = (16000000 / (2 * baud)) - 1;
UBRR0 = 0;
/* Setting the XCKn port pin as output, enables master mode. */
//XCKn_DDR |= (1<<XCKn);
//DDRD = DDRD | B00000010;
/* Set MSPI mode of operation and SPI data mode 0. */
UCSR0C = (1<<UMSEL01)|(1<<UMSEL00)|(1<<UDORD0);
/* Enable receiver and transmitter. */
UCSR0B = (1<<TXEN0);
/* Set baud rate. */
/* IMPORTANT: The Baud Rate must be set after the transmitter is enabled */
UBRR0 = _baud;
}
void USART_Send(uint8_t data)
{
/* Put data into buffer, sends the data */
UDR0 = data;
//Wait for the buffer to be empty
while ( !( UCSR0A & (1<<UDRE0)) );
}