Hi Dialog,
I am developing a SPI slave driver for DA14580, however, I could run it up to 250KHz. Could you guys give me some suggestion on how to make it faster? Thanks a lot.
Init function:
// Initialize SPI module
SetBits16(SPI_CTRL_REG,SPI_ON,0); // Close SPI module, if opened
SetBits16(SPI_CTRL_REG,SPI_WORD,0); // Set to 8-bit mode
SetBits16(SPI_CTRL_REG,SPI_SMN, 0x01); // Set SPI in SLAVE mode
SetBits16(SPI_CTRL_REG,SPI_POL, 0x0); // Mode 3: SPI_POL = 0
SetBits16(SPI_CTRL_REG,SPI_PHA, 0x0); // and SPI_PHA = 0
SetBits16(SPI_CTRL_REG,SPI_MINT, 0x1); // Enable SPI Maskable Interrupt to CPU
SetBits16(SPI_CTRL_REG1,SPI_FIFO_MODE,0x00); // Enable SPI RX and TX FIFOs
SetBits16 (SPI_CTRL_REG SPI_EN_CTRL 1);/ /启用年代PI EN pin for slave mode
SetBits16(SPI_CTRL_REG,SPI_ON,1); // Enable SPI module
// Configure SPI environment
NVIC_ClearPendingIRQ(SPI_IRQn);
NVIC_SetPriority(SPI_IRQn,0);
NVIC_EnableIRQ(SPI_IRQn);
In ISR:
void SPI_Handler(void)
{
static uint8_t data;
// Wait until data is ready
while (0xFF&GetBits16(SPI_CTRL_REG,SPI_INT_BIT) == 1)
{
data = 0xFF&GetWord16(SPI_RX_TX_REG0);
while ((GetBits16(SPI_CTRL_REG,SPI_TXH)==1)||(GetBits16(SPI_CTRL_REG1,SPI_BUSY)==1));
SetWord16(SPI_RX_TX_REG0, 0xFF&data);
SetWord16(SPI_CLEAR_INT_REG, 0x01);
}
}
Hi zwang308,
The SPI of the 580 in slave mode can support theoretically up to 4MHz (the clock provided from the master should be at least 4 times slower than the internal SPI clock of the 580), the problem is that the sampler of the SPI is quite sensetive to small spikes and reflections and mistakenly considers noise as pulses. Its not a matter of code (you can have a look at the implementation of SPI slave code - spi_hci_slave_init() in spi_hci.c file).
Some hints in order to properly clock data from the 580 acting as SPI slave:
1) The wire cables connecting the 580 to the external micro should be properly terminated and possibly shielded especially the wire that carries the clock cable.
2) Proper grounding between the two modules.
Thanks MT_dialog