Why the serial communication baudrate (UART0) cannot be set?
Is there any way to unlock this?
I tried also by setting registers, but i did not succeed.
I would like to have control over this.
Thank you, Leonardo
Is there any way to unlock this?
I tried also by setting registers, but i did not succeed.
Code:
const int led = 13;
static volatile uint8_t rx_buffer_head = 0;
static volatile uint8_t rx_buffer_tail = 0;
static volatile uint8_t tx_buffer_head = 0;
static volatile uint8_t tx_buffer_tail = 0;
static volatile uint8_t transmitting = 0;
void setup() {
serial_begin_115200();
pinMode(led, OUTPUT);
}
void loop() {
delay(1000);
Serial.write(0xC2);
Serial.write(0xB5);
Serial.write(0x0A);
blinkLed(100);
}
void blinkLed(int delay_ms) {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(delay_ms); // wait for some milliseconds
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
void serial_begin_115200(void)
{
SIM_SCGC4 |= 0x0400; // UART0 clock gate enabled
rx_buffer_head = 0;
rx_buffer_tail = 0;
tx_buffer_head = 0;
tx_buffer_tail = 0;
transmitting = 0;
PORTB_PCR16 = 0x0313; // configuration of RX pin
PORTB_PCR17 = 0x0344; // configuration of TX pin
// SBR([BDH BDL]) + (BRFA (C4[4:0]))/32 = (module_clock)/(16*Baudrate)
// SBR([BDH BDL]) + (BRFA (C4[4:0]))/32 = (96000000)/(16*115200)
// SBR([BDH BDL]) + (BRFA (C4[4:0]))/32 = 52.0833333
// SBR = 52 = [b00000000 b00110100] = [0x00 0x36]
// BRFA / 32 = 0.08333... -> ceil[BRFA] = 3 = b00000011 = 0x03
UART0_BDH = 0x00 & 0x1F;
UART0_BDL = 0x36 & 0xFF;
UART0_C4 = 0x03 & 0x1F;
UART0_C1 = 0x04; // idle line type select
UART0_TWFIFO = 2; // tx watermark, causes S1_TDRE to set
UART0_RWFIFO = 4; // rx watermark, causes S1_RDRF to set
UART0_PFIFO = 0x88; // FIFO Enable (TX & RX)
UART0_C2 = 0x3C; // reciever full interrupt or DMA transfer enable
// idle line interrupt enable
// transmitter enable, reciever enable
NVIC_SET_PRIORITY(45, 64);
NVIC_ENABLE_IRQ(45);
}
Thank you, Leonardo