2 posts / 0 new
Last post
jd@exp-eng.com
Offline
Last seen:2 years 7 months ago
加入:2014-10-22 04:34
da14580 as spi slave

Hello Dialog Team,

We have the da14580 setup as an SPI slave and the issue that we are having is that the SPI receive is on the DA14580 is reading all 0xFF's. I have searched for 'spi slave' on this forum and read all the threads but to no avail-I have been stuck on this for a few days now.

Here is what I have verified:

1. The Host is an Atmel microcontroller.
2.主机试图发送的数据是:{ 0xab, 0xcd, 0x0d, 0x0a }
3. The Host and DA14580 connections are good and wired as per UM-B-013.
4. The Host SPI is setup as a master in SPI MODE 0.
5. The Host SPI clock is set to 100000.
6. CS was verified low on a host data transfer. It was indeed low and verified on an oscilloscope.
7. CLK was present on a host data transfer and have verified this on an oscilloscope.
8. Data was present on MOSI on a host data transfer and have verified this on an oscilloscope.

In debug, I can see SPI_Handler being executed and running the spi_receive_data_isr() function. This code is very simple and all I want to do is transfer 4-bytes at this time. Here is the code:

#define RXB_EMPTY 0 // no data from atmel mcu
#define DRX_NO_EOM 1 // data received from atmel mcu, but end of message not received
#define DRX_EOMRX_DVAL 2 // data & end of message received from atmel mcu - data valid/good
#define DRX_EOMRX_DINV 3 // data & end of message received from atmel mcu - data invalid/bad

uint8_t spi_rxb[256];
uint8_t rxb_index = 0;
uint8_t rxb_status = RXB_EMPTY;

void spi_slave_init(void)
{
SetBits16(CLK_PER_REG, SPI_DIV, 0); // Set SPI internal clock divider
SetBits16(CLK_PER_REG, SPI_ENABLE, 1); // Enable clock for SPI

// 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); // Enable SPI EN pin for slave mode
SetBits16(SPI_CTRL_REG,SPI_ON,1); // Enable SPI module

// Configure SPI environment

NVIC_SetPriority(SPI_IRQn,0);
NVIC_EnableIRQ (SPI_IRQn);
}

static void spi_receive_data_isr(void)
{

// Read available received data to SPI environment buffer pointer
while (spi_data_rdy_getf())
{
// Read the received byte in the FIFO
spi_rxb[rxb_index] = spi_read_byte();
rxb_index++;

// process the data
rxb_status = process_spi_rxb_data();
}
}

void SPI_Handler(void)
{
spi_receive_data_isr();
}

uint8_t process_spi_rxb_data(void)
{
if (rxb_index >= 4)
{

if( spi_rxb[0] == 0xab && // I HAVE SET A BREAK POINT HERE
spi_rxb[1] == 0xcd &&
spi_rxb[2] == 0x0d &&
spi_rxb[3] == 0x0a) return DRX_EOMRX_DVAL;
else return DRX_NO_EOM;
}
else return DRX_NO_EOM;
}

The spi_slave_init() function is called in the periph_init function. The good news is the DA14580 does indeed receive the 4 byte SPI data, but the problem is all 0xFF's. I have confirmed CS, MOSI, and CLK and MOSI does indeed have data.

Please let me know if there is anything that I have missed on the code or anything else that I can verify. I am at a loss why I cannot get data to the DA14580.

Thanks again in advance

Device:
MT_dialog
Offline
Last seen:2 months 4 weeks ago
Staff
加入:2015-06-08 11:34
Hi jd@exp-eng.com,

Hijd@exp-eng.com,

I dont see anything wrong with the code, and as far as i can tell its quite the same with the prox_reporter_ext_spi example which initializes the 580's SPI in slave mode. The SPI clock on the master is quite low 100KHz so its ok and withing the limitation. What you should also check is that both of the modules are properly grounded (common ground), and that you should also apply termination to the connections along the clock connection.

The fact that you always get 0xFF and you see data on the MOSI line sounds a bit weird, if not the data that you send, in your buffers you should be able to see some sort of data, as far i can tell the SPI module of the 580 correctly gets the clock from the master (since you get the interrupt) but the sampler of the module checks a line that is pulled up and you get only 0xFF, so check if you have configured the GPIO pins for the SPI properly and the MISO and MOSI lines are connected to the pins with the correct functionality.

Thanks MT_dialog