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.

TMS570LS3137: sciSetBaudrate() by HalCoGen version 4.7

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

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

  • Hello,
    For Asynchronous baud value 115200 and VCLK1 90MHz, the correct prescaler value for BRS is 48.
    sciSetBaudrate must be called with baud in Hertz.
    The floor(x) function returns the largest integral value not greater than x. With adding 0.5 floor rounds-off to the closest integer.

    Best regards,
    Miro
  • 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

  • Hello,

    I have tested sciSetBaudrate with 20 MHz as VCLK1, 115200 as baud.

    temp2 is 9.85 after temp2 = ((vclk)/((float64)temp))-1U;

    temp2 is 10 after temp2 = floor(temp2 + 0.5);

    Best regards,

    Miro

  • Hello Kalyan,
    Since there is no feedback from you, this makes me think that you have solved your issue with sci baud-rate. That is why I am closing this thread. You can always re-open it with writing after the last post or you can open new thread.

    Best regards,
    Miro