S32K1: LPUART BAUD register OSR bits stuck

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K1: LPUART BAUD register OSR bits stuck

Jump to solution
1,103 Views
trevor_oth
Contributor II

Hi.

My target MCU is a S32K144W on the S32K14W-Q064 evaluation board. I'm configuring the LPUART0 baud rate and I'm noticing that I cannot clear the lower 4 OSR bits in the BAUD register. Those bits default to 1 on reset, but should be writable/clearable afterward. I can set or clear the upper OSR bit, but the lower 4 bits are stuck, always set, and can't be cleared through any operation on that register.

Spoiler
Screenshot_RM_BAUD_OSR.png

Obviously that limits the function of the UART, and makes choosing an appropriate baud rate difficult. I have combed through the documentation several times but I can't find any mention of a restriction on these bits, or a condition that must be satisfied for them to be cleared or changed. Perhaps I missed it.

I found 2 other forum posts where a user mentions the same problem (though on a different part).

"So i noticed that only  value of 16 and 32 can be set in OSR field (15 and 31), any other value results in getting 16/32."

Unfortunately, I don't see a resolution.

https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K82F-uart-problem/m-p/845950

https://community.nxp.com/t5/Kinetis-Microcontrollers/LPUART0-baudrate/m-p/792047/highlight/true#M48...

Any thoughts on why these bits are stuck or how I can change them?

Thanks for your help!

Trevor

0 Kudos
Reply
1 Solution
977 Views
trevor_oth
Contributor II

Hi Robin,

I'm not using S32K1 RTD - I'm configuring the UART directly in the LPUART registers.

To clarify, I was trying clear the OSR and SBR bits first (using LPUART_BAUD_OSR_MASK and LPUART_BAUD_SBR_MASK), then set the required bits (using LPUART_BAUD_OSR(x) and LPUART_BAUD_SBR(x)) to get the baud rate that I need. The key is that if you clear all of the OSR bits, it will result in an oversampling ratio of 16, which is the same as the default with the lower 4 bits set. The reference manual says this, but doesn't appear to fully explain what happens when you clear the OSR bits.

Screenshot_RM_OSR.png

What I didn't understand was that if you clear all of the OSR bits, the hardware doesn't just interpret that as using an oversample ratio of 16, but instead it literally forces the 4 lower bits back to 1, back to the default setting. So you can't use the typical pattern of masking and clearing those bits first, then setting the bits you need. Instead you have to set the BAUD register all it once with the values that you need in all of the bit groups.

So by changing this:
IP_LPUART0->BAUD &= ~( LPUART_BAUD_OSR_MASK );
IP_LPUART0->BAUD |= ( LPUART_BAUD_OSR(10u) );
...

To this:
IP_LPUART0->BAUD = ( LPUART_BAUD_OSR(10u) | ... );

It looks like it is now working as expected.

Thanks again for your help.

Regards,
Trevor

View solution in original post

0 Kudos
Reply
3 Replies
978 Views
trevor_oth
Contributor II

Hi Robin,

I'm not using S32K1 RTD - I'm configuring the UART directly in the LPUART registers.

To clarify, I was trying clear the OSR and SBR bits first (using LPUART_BAUD_OSR_MASK and LPUART_BAUD_SBR_MASK), then set the required bits (using LPUART_BAUD_OSR(x) and LPUART_BAUD_SBR(x)) to get the baud rate that I need. The key is that if you clear all of the OSR bits, it will result in an oversampling ratio of 16, which is the same as the default with the lower 4 bits set. The reference manual says this, but doesn't appear to fully explain what happens when you clear the OSR bits.

Screenshot_RM_OSR.png

What I didn't understand was that if you clear all of the OSR bits, the hardware doesn't just interpret that as using an oversample ratio of 16, but instead it literally forces the 4 lower bits back to 1, back to the default setting. So you can't use the typical pattern of masking and clearing those bits first, then setting the bits you need. Instead you have to set the BAUD register all it once with the values that you need in all of the bit groups.

So by changing this:
IP_LPUART0->BAUD &= ~( LPUART_BAUD_OSR_MASK );
IP_LPUART0->BAUD |= ( LPUART_BAUD_OSR(10u) );
...

To this:
IP_LPUART0->BAUD = ( LPUART_BAUD_OSR(10u) | ... );

It looks like it is now working as expected.

Thanks again for your help.

Regards,
Trevor

0 Kudos
Reply
957 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Trevor,

Thank you for your information.

I hadn't noticed before that you can't clear the OSR bit separately; I saw that writing to the BAUD register in the RTD is also done all at once.

Best Regards,
Robin

0 Kudos
Reply
1,002 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Did you configure BAUD[BOTHEDGE]? If you are using S32K1 RTD, then you may need to configure it by refer to:

BAUD[OSR][BOTHEDGE] Lpuart_Uart_Ip_SetUp_Baudrate RTD.png


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "ACCEPT AS SOLUTION" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2196889%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K1%3A%20LPUART%20BAUD%20register%20OSR%20bits%20stuck%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2196889%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi.%3C%2FP%3E%3CP%3EMy%20target%20MCU%20is%20a%20S32K144W%20on%20the%26nbsp%3BS32K14W-Q064%20evaluation%20board.%20I'm%20configuring%20the%20LPUART0%20baud%20rate%20and%20I'm%20noticing%20that%20I%20cannot%20clear%20the%20lower%204%20OSR%20bits%20in%20the%20BAUD%20register.%20Those%20bits%20default%20to%201%20on%20reset%2C%20but%20should%20be%20writable%2Fclearable%20afterward.%20I%20can%20set%20or%20clear%20the%20upper%20OSR%20bit%2C%20but%20the%20lower%204%20bits%20are%20stuck%2C%20always%20set%2C%20and%20can't%20be%20cleared%20through%20any%20operation%20on%20that%20register.%3C%2FP%3E%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpoiler%3C%2FA%3E%3CNOSCRIPT%3E%20(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot_RM_BAUD_OSR.png%22%20style%3D%22width%3A%20867px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Screenshot_RM_BAUD_OSR.png%22%20style%3D%22width%3A%20867px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F363561i29FF63DC8D44B888%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot_RM_BAUD_OSR.png%22%20alt%3D%22Screenshot_RM_BAUD_OSR.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EObviously%20that%20limits%20the%20function%20of%20the%20UART%2C%20and%20makes%20choosing%20an%20appropriate%20baud%20rate%20difficult.%20I%20have%20combed%20through%20the%20documentation%20several%20times%20but%20I%20can't%20find%20any%20mention%20of%20a%20restriction%20on%20these%20bits%2C%20or%20a%20condition%20that%20must%20be%20satisfied%20for%20them%20to%20be%20cleared%20or%20changed.%20Perhaps%20I%20missed%20it.%3C%2FP%3E%3CP%3EI%20found%202%20other%20forum%20posts%20where%20a%20user%20mentions%20the%20same%20problem%20(though%20on%20a%20different%20part).%3C%2FP%3E%3CP%3E%3CEM%3E%22So%20i%20noticed%20that%26nbsp%3Bonly%26nbsp%3B%20value%20of%2016%20and%2032%20can%20be%20set%20in%20OSR%20field%20(15%20and%2031)%2C%20any%20other%20value%20results%20in%20getting%2016%2F32.%22%3C%2FEM%3E%3C%2FP%3E%3CP%3EUnfortunately%2C%20I%20don't%20see%20a%20resolution.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FKinetis-Microcontrollers%2FFRDM-K82F-uart-problem%2Fm-p%2F845950%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FKinetis-Microcontrollers%2FFRDM-K82F-uart-problem%2Fm-p%2F845950%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FKinetis-Microcontrollers%2FLPUART0-baudrate%2Fm-p%2F792047%2Fhighlight%2Ftrue%23M48190%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FKinetis-Microcontrollers%2FLPUART0-baudrate%2Fm-p%2F792047%2Fhighlight%2Ftrue%23M48190%3C%2FA%3E%3C%2FP%3E%3CP%3EAny%20thoughts%20on%20why%20these%20bits%20are%20stuck%20or%20how%20I%20can%20change%20them%3F%3C%2FP%3E%3CP%3EThanks%20for%20your%20help!%3C%2FP%3E%3CP%3ETrevor%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2198174%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K1%3A%20LPUART%20BAUD%20register%20OSR%20bits%20stuck%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2198174%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Trevor%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20your%20information.%3C%2FP%3E%0A%3CP%3EI%20hadn't%20noticed%20before%20that%20you%20can't%20clear%20the%20%3CSTRONG%3EOSR%3C%2FSTRONG%3E%20bit%20separately%3B%20I%20saw%20that%20writing%20to%20the%20%3CSTRONG%3EBAUD%3C%2FSTRONG%3E%20register%20in%20the%20RTD%20is%20also%20done%20all%20at%20once.%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3ERobin%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2197729%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K1%3A%20LPUART%20BAUD%20register%20OSR%20bits%20stuck%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2197729%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Robin%2C%3C%2FP%3E%3CP%3EI'm%20not%20using%20S32K1%20RTD%20-%20I'm%20configuring%20the%20UART%20directly%20in%20the%20LPUART%20registers.%3C%2FP%3E%3CP%3ETo%20clarify%2C%20I%20was%20trying%20clear%20the%20OSR%20and%20SBR%20bits%20first%20(using%20LPUART_BAUD_OSR_MASK%20and%20LPUART_BAUD_SBR_MASK)%2C%20then%20set%20the%20required%20bits%20(using%20LPUART_BAUD_OSR(x)%20and%20LPUART_BAUD_SBR(x))%20to%20get%20the%20baud%20rate%20that%20I%20need.%20The%20key%20is%20that%20if%20you%20clear%20all%20of%20the%20OSR%20bits%2C%20it%20will%20result%20in%20an%20oversampling%20ratio%20of%2016%2C%20which%20is%20the%20same%20as%20the%20default%20with%20the%20lower%204%20bits%20set.%20The%20reference%20manual%20says%20this%2C%20but%20doesn't%20appear%20to%20fully%20explain%20what%20happens%20when%20you%20clear%20the%20OSR%20bits.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot_RM_OSR.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Screenshot_RM_OSR.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F363762iCF10A95BC2C7762C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Screenshot_RM_OSR.png%22%20alt%3D%22Screenshot_RM_OSR.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EWhat%20I%20didn't%20understand%20was%20that%20if%20you%20clear%20all%20of%20the%20OSR%20bits%2C%20the%20hardware%20doesn't%20just%20interpret%20that%20as%20using%20an%20oversample%20ratio%20of%2016%2C%20but%20instead%20it%20literally%20forces%20the%204%20lower%20bits%20back%20to%201%2C%20back%20to%20the%20default%20setting.%20So%20you%20can't%20use%20the%20typical%20pattern%20of%20masking%20and%20clearing%20those%20bits%20first%2C%20then%20setting%20the%20bits%20you%20need.%20Instead%20you%20have%20to%20set%20the%20BAUD%20register%20all%20it%20once%20with%20the%20values%20that%20you%20need%20in%20all%20of%20the%20bit%20groups.%3C%2FP%3E%3CP%3ESo%20by%20changing%20this%3A%3CBR%20%2F%3EIP_LPUART0-%26gt%3BBAUD%20%26amp%3B%3D%20~(%20LPUART_BAUD_OSR_MASK%20)%3B%3CBR%20%2F%3EIP_LPUART0-%26gt%3BBAUD%20%3CSTRONG%3E%7C%3D%3C%2FSTRONG%3E%20(%20LPUART_BAUD_OSR(10u)%20)%3B%3CBR%20%2F%3E...%3C%2FP%3E%3CP%3ETo%20this%3A%3CBR%20%2F%3EIP_LPUART0-%26gt%3BBAUD%20%3CSTRONG%3E%3D%3C%2FSTRONG%3E%20(%20LPUART_BAUD_OSR(10u)%20%7C%20...%20)%3B%3C%2FP%3E%3CP%3EIt%20looks%20like%20it%20is%20now%20working%20as%20expected.%3C%2FP%3E%3CP%3EThanks%20again%20for%20your%20help.%3C%2FP%3E%3CP%3ERegards%2C%3CBR%20%2F%3ETrevor%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2197389%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K1%3A%20LPUART%20BAUD%20register%20OSR%20bits%20stuck%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2197389%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%3C%2FP%3E%0A%3CP%3EDid%20you%20configure%20BAUD%5BBOTHEDGE%5D%3F%20If%20you%20are%20using%20S32K1%20RTD%2C%20then%20you%20may%20need%20to%20configure%20it%20by%20refer%20to%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BAUD%5BOSR%5D%5BBOTHEDGE%5D%20Lpuart_Uart_Ip_SetUp_Baudrate%20RTD.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22BAUD%5BOSR%5D%5BBOTHEDGE%5D%20Lpuart_Uart_Ip_SetUp_Baudrate%20RTD.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F363686i9942927B0D23248A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22BAUD%5BOSR%5D%5BBOTHEDGE%5D%20Lpuart_Uart_Ip_SetUp_Baudrate%20RTD.png%22%20alt%3D%22BAUD%5BOSR%5D%5BBOTHEDGE%5D%20Lpuart_Uart_Ip_SetUp_Baudrate%20RTD.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EBest%20Regards%2C%3CBR%20%2F%3ERobin%3CBR%20%2F%3E-------------------------------------------------------------------------------%3CBR%20%2F%3ENote%3A%3CBR%20%2F%3E-%20If%20this%20post%20answers%20your%20question%2C%20please%20click%20the%20%22ACCEPT%20AS%20SOLUTION%22%20button.%20Thank%20you!%3C%2FP%3E%0A%3CP%3E-%20We%20are%20following%20threads%20for%207%20weeks%20after%20the%20last%20post%2C%20later%20replies%20are%20ignored%3CBR%20%2F%3EPlease%20open%20a%20new%20thread%20and%20refer%20to%20the%20closed%20one%2C%20if%20you%20have%20a%20related%20question%20at%20a%20later%20point%20in%20time.%3CBR%20%2F%3E-------------------------------------------------------------------------------%3C%2FP%3E%3C%2FLINGO-BODY%3E