Hi!
I want to test ezport on my board via frdm-kl43. I've tried simple SPI trasnmission and failed.
The code:
ini_spi();
SPI1_S & (SPI_S_SPRF_MASK); //initial clear of SPRF bit
while(1)
{
OSA_TimeDelay(100);
GPIO_DRV_ClearPinOutput(CS); //CS enable
SPI1_DL=0x55;
while (!(SPI1_S & (SPI_S_SPRF_MASK))); //wait SPRF to be setted up
GPIO_DRV_SetPinOutput(CS); //CS desable
}
And logic analyzer picture is attached. Chip select goes high before transmit is complete.( SPRF sets)
What is the root of my problem?
Solved! Go to Solution.
ok,i have done with it.
With the interrupt it worked out:
INT_SYS_InstallHandler(SPI1_IRQn,spi_interrupt_hndler);
NVIC_EnableIRQ(SPI1_IRQn);
INT_SYS_EnableIRQGlobal();
SPI1_S & (SPI_S_SPRF_MASK);
while(1)
{
OSA_TimeDelay(1000);
GPIO_DRV_ClearPinOutput(CS); //CS enable
spi_cnt=1; //2 symbols to sent
if(SPI1_S&(1<<SPI_S_SPTEF_SHIFT )) SPI1_DL=0x05; //read status reg
if(SPI1_S&(1<<SPI_S_SPTEF_SHIFT )) SPI1_DL=0x00; //here will be status reg answer
}
and the interrupt code:
void spi_interrupt_hndler(void)
{
SPI1_S&SPI_S_SPRF_MASK;
uint8_t a=SPI1_DL;
if(spi_cnt)
{
--spi_cnt;
}
else
{
GPIO_DRV_SetPinOutput(CS);
}
}
Note: for ezport to work you have to reset the CPU and push CS down before un-reset the target CPU. Than read Status register.
I hope it will help anyone.
Best regards, Alexey.
ok,i have done with it.
With the interrupt it worked out:
INT_SYS_InstallHandler(SPI1_IRQn,spi_interrupt_hndler);
NVIC_EnableIRQ(SPI1_IRQn);
INT_SYS_EnableIRQGlobal();
SPI1_S & (SPI_S_SPRF_MASK);
while(1)
{
OSA_TimeDelay(1000);
GPIO_DRV_ClearPinOutput(CS); //CS enable
spi_cnt=1; //2 symbols to sent
if(SPI1_S&(1<<SPI_S_SPTEF_SHIFT )) SPI1_DL=0x05; //read status reg
if(SPI1_S&(1<<SPI_S_SPTEF_SHIFT )) SPI1_DL=0x00; //here will be status reg answer
}
and the interrupt code:
void spi_interrupt_hndler(void)
{
SPI1_S&SPI_S_SPRF_MASK;
uint8_t a=SPI1_DL;
if(spi_cnt)
{
--spi_cnt;
}
else
{
GPIO_DRV_SetPinOutput(CS);
}
}
Note: for ezport to work you have to reset the CPU and push CS down before un-reset the target CPU. Than read Status register.
I hope it will help anyone.
Best regards, Alexey.