I want to use MKM34Z256VLL7 microcontroller in SPI slave mode, I configurated it but it doesn't work.
SPI0 IRQ interrupt is not working. and datas are not comming in receive buffer.
"
#include "MKM34Z7.h"
void SPI_Slave_Init(void) {
SIM->SCGC4 |= SIM_SCGC4_SPI0_MASK;
SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK;
PORTD->PCR[2] = PORT_PCR_MUX(2); // SCK
PORTD->PCR[3] = PORT_PCR_MUX(2); // MOSI
PORTD->PCR[4] = PORT_PCR_MUX(2); // MISO
PORTD->PCR[5] = PORT_PCR_MUX(2); // SS
SPI0->C1 = SPI_C1_SPE_MASK;
SPI0->C1 &= ~SPI_C1_MSTR_MASK;
SPI0->C2 = 0;
NVIC_SetPriority(SPI0_SPI1_IRQn, 2);
NVIC_EnableIRQ(SPI0_SPI1_IRQn);
SPI0->C1 |= SPI_C1_SPIE_MASK;
}
static volatile uint8_t receivedData;
static volatile uint8_t dataToSend = 0x55;
void SPI0_SPI1_IRQHandler(void) {
if (SPI0->S & SPI_S_SPRF_MASK) {
receivedData = SPI0->DL;
SPI0->DL = dataToSend;
}
}"
Hi,
I suppose that your code is correct.
void SPI0_SPI1_IRQHandler(void) {
if (SPI0->S & SPI_S_SPRF_MASK) {
receivedData = SPI0->DL;
SPI0->DL = dataToSend;
}
The SPI0->DL is both input and output data register.
Regarding your issue, if you do not read the DL, just write the DL register, what is the result?
Hope it can help you
BR
XiangJun Rong
Hi,
When you use the SPI of KM34 as slave, as you know that the SPI master drives the SCK and /CS signal and launch the spi transfer, pls sure you have connected the master and slave:
SPI master SPI slave
/CS /CS
SCK SCK
MOSI MOSI
MISO MISO
after the master launch the spi transfer, the slave spi can work and enter interrupt.
Pls check if you connect the spi master and slave and if the spi master has launched the data transfer.
Hope it can help you
BR
Xiangjun Rong