Hi team
I got a warning [arithmetic overflow in constant expression] for the following code, what have I done wrong??
This is the line with warning:
Warnings:
I got a warning [arithmetic overflow in constant expression] for the following code, what have I done wrong??
This is the line with warning:
Code:
SPBRG = (uint8_t) (416UL & 0x00FF);
Here is the full code:uart.c:25:: warning: (751) arithmetic overflow in constant expression
Code:
void Uart_init(uart_params_t *params) {
if (params == NULL) return;
TRISCbits.TRISC7 = 1U; // per datasheet
TRISCbits.TRISC6 = 1U; // per datasheet
TXSTAbits.TXEN = 1U; // enable TX
TXSTAbits.BRGH = 1U; // high speed
RCSTAbits.CREN = 1U; // enable continuous RX
BAUDCONbits.BRG16 = 1U; // enable 16-bit Baud rate
/*
* setup band rate
* BR = FOSC/[4 * (n+1)], n = BRG
*/
switch (params->br) {
case BR_9600:
SPBRGH = (uint8_t) (416UL >> 8U);
SPBRG = (uint8_t) (416UL & 0x00FF); // <<<<<<<<===== warning on this line
break;
case BR_14400:
SPBRGH = (uint8_t) (227U >> 8U);
SPBRG = (uint8_t) (227U & 0xFF);
break;
case BR_19200:
SPBRGH = (uint8_t) (207U >> 8U);
SPBRG = (uint8_t) (207U & 0xFF);
break;
case BR_38400:
SPBRGH = (uint8_t) (103U >> 8U);
SPBRG = (uint8_t) (103U & 0xFF);
break;
case BR_57600:
SPBRGH = (uint8_t) (68U >> 8U);
SPBRG = (uint8_t) (68U & 0xFF);
break;
default:
SPBRGH = (uint8_t) (207U >> 8U);
SPBRG = (uint8_t) (207U & 0xFF);
break;
}
/* setup TX and RX interrupt */
if (params->enableRXInt) PIE1bits.RCIE = 1U;
if (params->enableTXInt) PIE1bits.TXIE = 1U;
RCSTAbits.SPEN = 1U; // enable UART
}