0

I'm trying to convert an Arduino Uno program for use with the ESP2866. I've converted most of the program successfully, but there are a few lines I can't seem to figure out. For example,

  UCSR0B = 0b10011101;
  UCSR0B = 0b10011100;

These lines result in the following error:

Compilation error: 'UCSR0B' was not declared in this scope

My understanding is that these lines modify parameters within one of the Uno's serial registers. Is it possible to do the equivalent action on the ESP? I have tried researching this but have found very little info online. I am using Arduino IDE v2.2.1. Thank you!

1
  • When porting software from one target to another, especially if it accesses hardware directly, always needs reading and understanding the documentation of both targets. Before you post a question here, you are supposed to do this homework, which you apparently did not. Commented Dec 28, 2023 at 12:51

1 Answer 1

1

UCSR0B is the UART Control and Status Register on an ATMEGA328, the processor used on many Arduino models. This is extract from the ATMEGA328 datasheet shows what the bits do:

enter image description here

Setting it to 0b10011101 enables RXCIE, RXEN,TXEN, UCSZ2 and TXB, and setting to the 0b10011100 sets all of the bits except TXB. Setting UCSZ2 enables 9-bit mode, and setting or clearing TXB sets or clears the ninth bit for transmitted data.

Taking a quick look at the ESP8266 UART config, the UART supports a maximum of 8 bits, so if your app definitely requires 9 bits, you won't be able to do it on an ESP8266.

typedef enum {
    UART_DATA_5_BITS = 0x0,    /*!< word length: 5bits*/
    UART_DATA_6_BITS = 0x1,    /*!< word length: 6bits*/
    UART_DATA_7_BITS = 0x2,    /*!< word length: 7bits*/
    UART_DATA_8_BITS = 0x3,    /*!< word length: 8bits*/
} uart_word_length_t;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.