Name : main.c Author : Version : Copyright : Copyright (C) Description : main definition =============================================================================== */ #ifdef __USE_CMSIS #include "LPC11xx.h" #endif /* SSP Status register */ #define SSPSR_TFE (0x1<<0) #define SSPSR_TNF (0x1<<1) #define SSPSR_RNE (0x1<<2) #define SSPSR_RFF (0x1<<3) #define SSPSR_BSY (0x1<<4) /* SSP CR0 register */ #define SSPCR0_DSS (0x1<<0) #define SSPCR0_FRF (0x1<<4) #define SSPCR0_SPO (0x1<<6) #define SSPCR0_SPH (0x1<<7) #define SSPCR0_SCR (0x1<<8) /* SSP CR1 register */ #define SSPCR1_LBM (0x1<<0) #define SSPCR1_SSE (0x1<<1) #define SSPCR1_MS (0x1<<2) #define SSPCR1_SOD (0x1<<3) /* SSP Interrupt Mask Set/Clear register */ #define SSPIMSC_RORIM (0x1<<0) #define SSPIMSC_RTIM (0x1<<1) #define SSPIMSC_RXIM (0x1<<2) #define SSPIMSC_TXIM (0x1<<3) /* SSP0 Interrupt Status register */ #define SSPRIS_RORRIS (0x1<<0) #define SSPRIS_RTRIS (0x1<<1) #define SSPRIS_RXRIS (0x1<<2) #define SSPRIS_TXRIS (0x1<<3) /* SSP0 Masked Interrupt register */ #define SSPMIS_RORMIS (0x1<<0) #define SSPMIS_RTMIS (0x1<<1) #define SSPMIS_RXMIS (0x1<<2) #define SSPMIS_TXMIS (0x1<<3) /* SSP0 Interrupt clear register */ #define SSPICR_RORIC (0x1<<0) #define SSPICR_RTIC (0x1<<1) /***************************************************************************** ** Function name: SSP_IOConfig ** ** Descriptions: SSP port initialization routine ** ** parameters: None ** Returned value: None ** *****************************************************************************/ void SSP_IOConfig( uint8_t portNum ) { if ( portNum == 0 ) { LPC_SYSCON->PRESETCTRL |= (0x1<<0); LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<11); LPC_SYSCON->SSP0CLKDIV = 0x0A; /* Divided by 2 */ LPC_IOCON->PIO0_9 &= ~0x1f; LPC_IOCON->PIO0_9 |= 0x9; /* SSP MOSI */ } return; } /***************************************************************************** ** Function name: SSP_Init ** ** Descriptions: SSP port initialization routine ** ** parameters: None ** Returned value: None ** *****************************************************************************/ void SSP_Init( uint8_t portNum ) { if ( portNum == 0 ) { /* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 15 */ LPC_SSP0->CR0 = 0x000F; /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ LPC_SSP0->CPSR = 0x0A; /* Set SSPINMS registers to enable interrupts */ /* enable all error related interrupts */ LPC_SSP0->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM; /* Device select as master, SSP Enabled */ /* Master mode */ LPC_SSP0->CR1 = SSPCR1_SSE; } return; } /***************************************************************************** ** Function name: SSP_Send ** ** Descriptions: Send a block of data to the SSP port, the ** first parameter is the buffer pointer, the 2nd ** parameter is the block length. ** ** parameters: port #, buffer pointer, and the block length ** Returned value: None ** *****************************************************************************/ void SSP_Send( ) { uint8_t Dummy = Dummy; while(1) { /* Move on only if NOT busy and TX FIFO not full. */ while ( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF ); LPC_SSP0->DR = 0xAA; //Manually coded output byte while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO on MISO. Otherwise, when SSP0Receive() is called, previous data byte is left in the FIFO. */ Dummy = LPC_SSP0->DR; } return; } /****************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { SSP_IOConfig(0); SSP_Init(0); while (1) { SSP_Send(); } return 0; } /****************************************************************************** ** End Of File ******************************************************************************/ |
Sorry if it's bad form to resurrect an 8 year old thread, but this was still the first search result on google.
I ran into this issue on the S32k148 while working with WS2812s, and after poking around it seems the framing was being caused by overhead from operating in interrupt mode. Switching to DMA for SPI calls resolved the big pauses between SPI frames. I'm not even sure if that's an option for this chip, but for anyone else who has the same issue that was a the fix for this symptom on a different system.