Hi,
I'm having some strange things happening in CCS5, I am using this with the FR5739 experimenter board to compile an application. Below is the function that I am having issues with. I'll be just focusing on the variables n , n_frac, n_Int . I have attached pictures from breakpoints from (1) initial, (2) n , (3), n_frac, (4) n_Int.
At (1) the registers are correct besides n_Int being -15872 even though I initialized to 0 at the beginning... no idea why this is happening
At (2) freq somehow changed... any ideas? I don't get how this changed. However, n is correct. (n_frac also changed to something else but still essentially 0)
At (3) baud changed now so something way off. However, n_frac is correct result. Also ucbrsx is some negative number now...
At (4) n_Int is correct
void EUSCI_A0_init(long baud, long freq){
double n = 0.0;
char os16 = 0;
int n_Int = 0;
double n_frac = 0;
int ucbrx = 0;
int ucbrfx = 0;
int ucbrsx = 0;
// Configure UART A0 pins P2.0 & P2.1
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTLW0 = UCSWRST;
UCA0CTLW0 = UCSSEL_2; // Set SMCLK as UCLk
UCA0CTLW1 = UCGLIT_3; // 200ns deglitch time
/*
* 1) Calculate N = freq/baud (if N > 16, go to step 3, else step 2)
* 2) OS16=0, UCBRx = INT(N) (go step 4)
* 3) OS16=1, UCBRx = INT (N/16), UCBRFx = INT( (N/16) - INT(N/16)) * 16)
* 4) UCBRSx can be found by looking up the fractional table
*/
n = (double)freq / (double)baud; // get N
n_frac = n - ((int)n); // get fractional portion of N
n_Int = n; // get INT portion of N
ucbrsx = getUCBRSX(n_frac); // get UCBRx from the table
if (n>16){
ucbrx = (int)(n/16);
ucbrfx = (int)( (n/16 - (int)(n/16))*16);
os16 = 1;
}else{
os16 = 0;
ucbrx = n_Int;
}
// baud rate
// N = freq/baud
// N = 8.681
// OS16 = 0, UCBRx = INT(N)
//
UCA0BRW = ucbrx;// 115200 baud
UCA0MCTLW = os16 + (ucbrfx << 4) + (ucbrsx << 8);
UCA0CTL1 &= ~UCSWRST; // release from reset
UCA0IE = UCRXIE + UCTXIE; // Enable USCI_A0 RX/TX interrupt
/*
while(counter<7)
{
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = TX_Buffer[counter];
counter++;
}
*/
}
(1)
(2)
(3)
(4)
Any help is appreciated.
Thanks,
Cris