This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I am using "sciSetBaudrate" API function generated by HALCOGEN version 4.7 to updated SCI interface baud rate.below the API code generated by HALCOGEN
void sciSetBaudrate(sciBASE_t *sci, uint32 baud)
{
float64 vclk = 90.000 * 1000000.0;
uint32 f = ((sci->GCR1 & 2U) == 2U) ? 16U : 1U;
uint32 temp;
float64 temp2;
/*SAFETYMCUSW 96 S MR:6.1 <APPROVED> "Calculations including int and float cannot be avoided" */
temp = (f*(baud));
temp2 = ((vclk)/((float64)temp))-1U;
temp2 = floor(temp2 + 0.5); /* Rounding-off to the closest integer */
sci->BRS = (uint32)((uint32)temp2 & 0x00FFFFFFU);
}
I am trying to set baud rate as 115200 for which the prescaler value will be 10. "floor" function is returning correct prescaler value but the value copied in to temp2 variable is wrong there by configuring wrong prescaler vale. can you please help me to fix this issue?
Thanks,
Kalyan
Hi Miro,
Thanks for your response. we are using a custom hardware where VCLK is 20MHZ. And the theoretical BRS is 10. i used the sciSetBaudrate API to set BRS register. while debugging i could see floor function is returning correct value (i.e. 10). but the temp2 value is returned is 1076101120.0. I could see the correct prescaler value in D0_H and D0_L registers, but the instructions highlighted in red box in below screenshot manipulates returned value. By the way my code base uses floor function definition in s_floor.c file correct me if this is a wrong one.
below is the screenshot of the assembly code while debugging:
Thanks,
Kalyan