Hi, I'm trying to debug a SPI comunication master-slave, but it doesn't work. I have modified a SDK examples spi_polling_b2b_transfer_master and spi_polling_b2b_transfer_slave. The master sends the data correctly, but the slave doesn't receive the data. I think there is a problem with the function SPI_SlaveTrasfertNonBlocking, because if I put a breakpoint in the callback when I debug the code, it never enter in. In both the codes I have menaged the chip select like GPIO.
Below you can find the code about SPI master and slave.
MASTER:
while(1)
{
port_state = GPIO_PortRead(GPIO, APP_SW_PORT);
if ((!(port_state & (1 << APP_SW_PIN))))
{
/*Start Transfer*/
xfer.txData = srcBuff;
xfer.dataSize = 64;
xfer.configFlags = kSPI_FrameAssert;
GPIO_PinWrite(GPIO, 0, 4, 0);
SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
GPIO_PinWrite(GPIO, 0, 4, 1);
for(i=0; i<10000000; i++) asm("NOP");
}
}
SLAVE:
void pint_intr_callback(pint_pin_int_t pintr, uint32_t pmatch_status)
{
flag=1;
}
static void slaveCallback(SPI_Type *base, spi_slave_handle_t *slaveHandle, status_t status, void *userData)
{
slaveFinished = true;
}
while (1)
{
PINT_EnableCallbackByIndex(PINT, kPINT_PinInt0);
if(flag==1){
xfer.txData=sendBuff;
xfer.rxData = receiveBuff;
xfer.dataSize = 64;
SPI_SlaveTransferNonBlocking(EXAMPLE_SPI_SLAVE, &handle, &xfer);
while (slaveFinished != true)
{
}
}
}
best regards.
Hi, as already said the demo SDK without any changes works. This days I have modified the demo, the chip select is handled as GPIO for both master and slave. The Master sends the data to the slave when I push the botton correctly , but if I start to menage the slave's chip select as GPIO the code doesn't work. I have configured the pin in the Slave side as a digital input, and I have initialized the GPIO port and pin.
gpio_pin_config_t led_config = {
kGPIO_DigitalInput,
};
GPIO_PortInit(GPIO, 0);
GPIO_PinInit(GPIO, 0, 23, &led_config);
BOARD_InitPins():
const uint32_t port0_pin23_config = (/* Pin is configured as GPIO */
IOCON_PIO_FUNC0 |
/* No addition pin function */
IOCON_PIO_MODE_INACT|
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT0 PIN28 (coords: 44) is configured as PIO0_28 */
IOCON_PinMuxSet(IOCON, 0U, 23U, port0_pin23_config);
I noticed that the state of the slave's chip select pin doesn't change and is always equals to 1, also when the master starts to send the data to the slave.
Why doesn't the code work, if I start to menage the slave's chip select as GPIO?
Below you can find the code about SPI master and slave.
MASTER:
for (i = 0; i < BUFFER_SIZE; i++)
{
srcBuff[i] = i;
}
while (1)
{
port_state = GPIO_PortRead(GPIO, APP_SW_PORT);
if ((!(port_state & (1 << APP_SW_PIN))))
{
/*Start Transfer*/
xfer.txData = srcBuff;
xfer.dataSize = 64;
xfer.configFlags = kSPI_FrameAssert;
GPIO_PinWrite(GPIO, 0, 4, 0);
SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
GPIO_PinWrite(GPIO, 0, 4, 1);
for(i=0; i<10000000; i++) asm("NOP");
}
}
}
SLAVE:
for (i = 0; i < 64; i++)
{
sendBuff[i] = i;
}
while (1)
{
state= GPIO_PinRead(GPIO, 0, 23);
if (state==0){
flag=1;
}
/* receive data from master */
xfer.txData = sendBuff;
xfer.rxData = receiveBuff;
xfer.dataSize = sizeof(sendBuff);
SPI_SlaveTransferNonBlocking(EXAMPLE_SPI_SLAVE, &handle, &xfer);
while (slaveFinished != true)
{
}
}
}
in attach there is the screen shot of the logical analyzer.
BR
Hello @elix
So why do you configure chip select pin as gpio?
If used as gpio, try to directly send data, not use the function
SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
Hi @Alice_Yang, thanks for the answer. This days I have tried the SKD demo whitout any changes and now it works. I have found that the problem isnt' in the function SPI_SlaveTrasfertNonBlocking, but when I started to menage the slave's chip select like a GPIO the code doesn't work.
BR
Hi, tanks for the answer, this day I have tried SDK demo without any changes and it works. I have found that the problem isn't in the function SPI_SlaveTrasfertNonBlocking, but when I started to menage the slave's chip select like GPIO the code doesnt' work.
Best reguards
Hello @elix
Please tell us which chip do you use.
What about your board? DEMO board from nxp or your own board?
And how about demo working without any change?
BR
Alice
Hi, I'm using the evaluation kit LPC55s06 like a Master and our board like a slave.
yes, I have tried the demo working without any changes, the master sends the data correctly (a vector from 0 to 64) but the slave doesn't reply the same.
Unlike the demo working, in my code I menage the chip select like a GPIO, the data is sent from the master when I push the button SW1 and the slave would start to receive the data when the chip select goes down, but it doesn't work.
Best reguard
Hello @elix
Recommend you first using SDK demo without any change.
I have tested the demo on my side with EVK boards, working well.
Refer to readme.txt to connect hardware.
BR
Alice