Hi,
I try to send 2 frames, each of 8 bits. I want to do this without the SSEL line to go high between frames. It is active low.
I have attached my code below.
Going through the datasheet it seems that I have to change the EOT bit to 0 for the first byte. Then EOT need to be sat to 1 with the transmit of the second byte.
But it does not work. My code just hangs and there is no transmit.
It works fine transmitting 1 frame
Any advice?
Thank you
void spi_setup()
{
SYSCON->SYSAHBCLKCTRL0 |= (1<<11); //Enable clock for SPI0
SWM0->PINASSIGN_DATA[3] &= ~(0xFF<<24);
SWM0->PINASSIGN_DATA[3] |= (25<<24); //Assign SCK to GPIO0_25
SWM0->PINASSIGN_DATA[4] &= ~(0xFF<<0);
SWM0->PINASSIGN_DATA[4] |= (27<<0); //Assign MOSI to GPIO0_27
SWM0->PINASSIGN_DATA[4] &= ~(0xFF<<16);
SWM0->PINASSIGN_DATA[4] |= (26<<16); //Assign SSEL0 to GPIO0_26
SYSCON->FCLKSEL[9] = 1; //Select Main_clk as source for SPI0
SPI0->DIV = 10;
SPI0->CFG = (1 << 0) | // Enable SPI0
(1 << 2) | // Master mode
(0 << 3) | // LSB First mode disabled
(0 << 4) | // CPHA = 0
(0 << 5) | // CPOL = 0
(0 << 8); // SPOL = 0
SPI0->DLY |= (2<<8); // Frame delay = 2 SPI clock cycles
SPI0->TXCTL = (1 << 20) | // set End Of Transfer
(1 << 21) | // set End Of Frame
(1 << 22) | // RXIGNORE, otherwise SPI hangs until
// we read the data register
((8 - 1) << 24); // 8 bit frames
}
void spi_tx(unsigned char data)
{
// Wait for MSTIDLE, should be a no-op since we are waiting after
// the transfer.
while (!(SPI0->STAT & (1 << 8)));
// Wait for TXRDY
while (!(SPI0->STAT & (1 << 1)));
SPI0->TXDATCTL = (0<<21)|(0<<20)|(data<<0);
// Wait for the transfer to finish
while (!(SPI0->STAT & (1 << 8)));
SPI0->TXDATCTL = (1<<20)|(data<<0);
//SPI0->TXDAT = data;
// Wait for the transfer to finish
while (!(SPI0->STAT & (1 << 8)));
// Force END OF TRANSFER
SPI0->STAT = (1 << 7);
}
Hi
I got it to work without the example code.
Thx
Hello ,
Recommend you refer to the SPI demo under SDK.
And if still can't maintain low, directly use gpio to control slave selection.
BR
Alice