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: Baud rate generation on SCI2 periphery of TMS570LS31x

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

Hello,

I would like to use LIN configured as SCI2 periphery on TMS570LS31x MCU to transmit serial data on the frequency of 921600 Hz. The MCU is clocked from external 40 MHz source and HALCoGen IDE 04.07.01 is used to generate the HAL source code.

Based on the reference manual SPNU499C and section 26.16.12, the baud rate should be computed as follows:

        Asynchronous baud value = ( VCLK Frequency / (16 * (P + 1 + M/16 ) ) )

I assume the P and M dividers should be set to P=1 and M=11 to get as precise baud rate as possible, as follows:

        Asynchronous baud value = ( 40 MHz / (16 * (1 + 1 + 11/16 ) ) ) = 930233 Hz

The HALCoGen IDE sets P and M dividers to P=2 and M=0, so the baud rate equals to 833333 Hz. Unfortunately, I have not found a way to force the HALCoGen IDE to set optimal P and M dividers and generate adequate baud rate for this application.

Is there anything I have done incorrectly in the configuration please?

Regards,

Peter

  • Hi Peter,

    The M-divider is not implemented in HALCoGen. You need to write M-divider to BRS register manually.

  • QJ Wang,

    thank you for clarifying this. HALCoGen removes everything out of /* USER CODE BEGIN (X) */ and /* USER CODE END */ so I cannot change the line of code which sets the BRS register. I suspect the only solution is to write own sciInit() function.

    Is there any effective solution than creating another init function for SCI please?

    Thank you,

    Peter

  • Hi Peter,

    You can insert your own code to the user code section. The code in this section should not be removed. for example,

    /* USER CODE BEGIN (3) */
    sciREG4->BRS = 489U | (0x3 << 24);
    /* USER CODE END */

    I added my code to the user code section 3 in sciInit(). The code will be unchanged after HALCoGen re-generates code.

  • QJ Wang,

    Thank you for suggestion. Will this be accepted by SCI periphery as the BRS register is configured after the periphery is enabled? As far as I know, in general the registers should be configured before the periphery is enabled and clocked.

  • Hi Peter,

    The SWnRESET bit in SCIGCR1 enables you to keep the TX and RX state machines under reset.

    The sciSetBaudrate() generated by HALCOGen does not follow SWnRST=0 requirement. This is a SW bug. Thanks for pointing this out.