Need help about flexio emulating uart

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Need help about flexio emulating uart

1,024 次查看
chunyuan_zhu
Contributor I

I am using S32K148 mcu to emulate uart with flexio. The configuration of register is shown as follows:

PCC->PCCn[77] |= 0x40000000u;                 /* Enable clock for PORTE */
PORTE->PCR[4] |= PORT_PCR_MUX(6);     /*Set PE4 to flexIO D6 mode, tx */
PORTE->PCR[5] |= PORT_PCR_MUX(6);     /*Set PE5 to flexIO D7 mode, rx */

PCC->PCCn[PCC_FlexIO_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */
PCC->PCCn[PCC_FlexIO_INDEX] &= ~PCC_PCCn_PCS_MASK; /* clear clk source selection */
PCC->PCCn[PCC_FlexIO_INDEX] |= PCC_PCCn_PCS(1); /* Clock Src= 1 (SOSCDIV2_CLK) */
PCC->PCCn[PCC_FlexIO_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clock  */

/* Shifter Configuration*/
FLEXIO->SHIFTCFG[0]      |= FLEXIO_SHIFTCFG_SSTOP(0x03) /* Stop bit enable on logic 1*/
                                             | FLEXIO_SHIFTCFG_SSTART(0x02); /* Start bit 0 before loading the data on first shift*/

FLEXIO->SHIFTCTL[0]       |= FLEXIO_SHIFTCTL_TIMSEL(0X00) /* Select Timer 0*/
                                             | FLEXIO_SHIFTCTL_TIMPOL(0x00) /* Shift on pos edge*/
                                             | FLEXIO_SHIFTCTL_PINCFG(0x03) /* Shift as output*/
                                             | FLEXIO_SHIFTCTL_PINSEL(0x06) /* FXIO D6 as Tx*/
                                             | FLEXIO_SHIFTCTL_PINPOL(0x00) /* Pin active high*/
                                             | FLEXIO_SHIFTCTL_SMOD(0x02); /* Shifter in Tx mode*/


/* Timer Configuration*/
FLEXIO->TIMCFG[0]            |= FLEXIO_TIMCFG_TIMDEC(0x00) /* Counter Decrement of FlexIO clock*/
                                               | FLEXIO_TIMCFG_TIMDIS(0x02) /* Timer disable on Timer compare */
                                               | FLEXIO_TIMCFG_TIMENA(0x02) /* Timer enable on trigger high */
                                               | FLEXIO_TIMCFG_TSTOP(0x02) /* Stop bit is enabled on timer disable */
                                               | FLEXIO_TIMCFG_TSTART(0x01); /* Enable start bit*/


FLEXIO->TIMCTL[0]             |= FLEXIO_TIMCTL_TRGSEL(0x01) /* Trigger on shifter 0 status flag*/
                                              | FLEXIO_TIMCTL_TRGPOL(0x00) /* Trigger active high*/
                                              | FLEXIO_TIMCTL_TRGSRC(0x01) /* Internal Trigger*/
                                              | FLEXIO_TIMCTL_TIMOD(0x01); /* Baud rate mode*/


/* Time Compare*/
*/
FLEXIO->TIMCMP[0] |= FLEXIO_TIMCMP_CMP(0x0F44); /* Baud rate at 115200*/

FLEXIO->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;

The result is that PTE4 is always high. Is someone can help this?

0 项奖励
3 回复数

819 次查看
razva_tilimpea
NXP Employee
NXP Employee

Hi,

I'm not expert in FlexIO, but in SDK we already have the UART driver over FlexIO and basic example which explain how to use it. If is not suitable for your application to use SDK you can use our driver as inspiration.

Best regards,

Razvan

0 项奖励

819 次查看
chunyuan_zhu
Contributor I

Hi,

I copy code from "flexio_hw_access.h" to mine,  but I got problem at setting flexio enable.

/* reset */
regValue = FLEXIO->CTRL;
regValue &= (uint32_t)(~(FLEXIO_CTRL_SWRST_MASK));
regValue |= FLEXIO_CTRL_SWRST(TRUE);  /* in debugger, regValue = 2 */
FLEXIO->CTRL = (uint32_t)regValue;
FLEXIO->CTRL = 0x0U;
/* enable */
regValue = (uint32_t)FLEXIO->CTRL;
regValue &= (uint32_t)(~(FLEXIO_CTRL_FLEXEN_MASK));
regValue |= FLEXIO_CTRL_FLEXEN(TRUE); /* in debugger, regValue = 2 */
FLEXIO->CTRL = (uint32_t)regValue;
regValue = FLEXIO->CTRL; /* in debugger, regValue = 0 */

regValue is defined as volatile uint32_t regValue = 0u.

0 项奖励

819 次查看
chunyuan_zhu
Contributor I

As the debugger shows, CTRL is still 0 after set. Is there any extra configuration I missed?

Thanks.

0 项奖励