Clock out 4 bytes/frame in SPI using flexio

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

Clock out 4 bytes/frame in SPI using flexio

1,111 Views
sokolbiba
Contributor I

Hi guys, 
I am working on a project with the FRDM-K28F board. My project requires that the each SPI frame should have 4 bytes (32 clocks) before the PCS goes high again. I have figuret out that the flexio supports 8 and 16 bits per frame (correct me if I am wrong). Does anyone know how to configure it to clock out 32bits before PCS goes high. Below is a screen shot of how it is working now (2 bytes/frame).
Thank you!

Labels (1)
0 Kudos
Reply
3 Replies

976 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sokol,

Obviously, the FlexIO module of K28F supports 32 bits(4 bytes)  frame for spi protocol, because the shifter is 32 bits. You can refer to the FLEXIOx_TIMCMPn, the upper 8-bits configure the number of bits in each word equal to (CMP[15:8] + 1) / 2, if you set the TIMOD bits with 01 in binary in FLEXIO_TIMCTLn register which means "Dual 8-bit counters baud/bit mode".

In conclusion, you should set the CMP[15:8] as 0x3F for 32 bits transfer.

Hope it can help you

BR

XiangJun rong

0 Kudos
Reply

976 Views
sokolbiba
Contributor I

Hi XiangJun,

Thank you for your reply. Basically there are two timers that flexio uses for the SPI. One timer is for the SCLK and the other one is for the CSn. Below you will find the current configuration about the timerconfig. I tried to modify what you said but it seems that is not helpful in this case. 

/*3. Configure the timer 0 for SCK. */
timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(base->shifterIndex[0]);
timerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow;
timerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
timerConfig.pinConfig = kFLEXIO_PinConfigOutput;
timerConfig.pinSelect = base->SCKPinIndex;
timerConfig.pinPolarity = kFLEXIO_PinActiveHigh;
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitBaudBit;
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
timerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput;
timerConfig.timerReset = kFLEXIO_TimerResetNever;
timerConfig.timerDisable = kFLEXIO_TimerDisableOnTimerCompare;
timerConfig.timerEnable = kFLEXIO_TimerEnableOnTriggerHigh;
timerConfig.timerStop = kFLEXIO_TimerStopBitEnableOnTimerDisable;
timerConfig.timerStart = kFLEXIO_TimerStartBitEnabled;

timerDiv = srcClock_Hz / masterConfig->baudRate_Bps;
timerDiv = timerDiv / 2 - 1;

timerCmp = ((uint32_t)(masterConfig->dataMode * 2 - 1U)) << 8U;
timerCmp |= timerDiv;

timerConfig.timerCompare = timerCmp;

FLEXIO_SetTimerConfig(base->flexioBase, base->timerIndex[0], &timerConfig);

/* 4. Configure the timer 1 for CSn. */
timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_TIMn(base->timerIndex[0]);
timerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveHigh;
timerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
timerConfig.pinConfig = kFLEXIO_PinConfigOutput;
timerConfig.pinSelect = base->CSnPinIndex;
timerConfig.pinPolarity = kFLEXIO_PinActiveLow;
timerConfig.timerMode = kFLEXIO_TimerModeSingle16Bit;
// timerConfig.timerMode = kFLEXIO_TimerModeDual8BitBaudBit;
timerConfig.timerOutput = kFLEXIO_TimerOutputOneNotAffectedByReset;
timerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput;
timerConfig.timerReset = kFLEXIO_TimerResetNever;
timerConfig.timerDisable = kFLEXIO_TimerDisableOnPreTimerDisable;
timerConfig.timerEnable = kFLEXIO_TimerEnableOnPrevTimerEnable;
timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
timerConfig.timerStart = kFLEXIO_TimerStartBitDisabled;

timerConfig.timerCompare = 0xFFFFU;
// timerConfig.timerCompare = 0x3F;
FLEXIO_SetTimerConfig(base->flexioBase, base->timerIndex[1], &timerConfig);

Regards,

Sokol

0 Kudos
Reply

976 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sokol,

/*3. Configure the timer 0 for SCK. */
timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(base->shifterIndex[0]);
timerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow;
timerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
timerConfig.pinConfig = kFLEXIO_PinConfigOutput;
timerConfig.pinSelect = base->SCKPinIndex;
timerConfig.pinPolarity = kFLEXIO_PinActiveHigh;
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitBaudBit;
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
timerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput;
timerConfig.timerReset = kFLEXIO_TimerResetNever;
timerConfig.timerDisable = kFLEXIO_TimerDisableOnTimerCompare;
timerConfig.timerEnable = kFLEXIO_TimerEnableOnTriggerHigh;
timerConfig.timerStop = kFLEXIO_TimerStopBitEnableOnTimerDisable;
timerConfig.timerStart = kFLEXIO_TimerStartBitEnabled;

timerDiv = srcClock_Hz / masterConfig->baudRate_Bps;
timerDiv = timerDiv / 2 - 1;

timerCmp =0x3F<<8; //Rong write  ((uint32_t)(masterConfig->dataMode * 2 - 1U)) << 8U;
timerCmp |= timerDiv;

timerConfig.timerCompare = timerCmp;

FLEXIO_SetTimerConfig(base->flexioBase, base->timerIndex[0], &timerConfig);

For the above code, even if I change the high byte of Timer0 compare register to 0x3F, it is changed back to 0x0F somewhere else by the code.

I am debugging the code now.

BR

Xiangjun Rong

0 Kudos
Reply