SPI Communication LCPXPRESSO with mbed

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI Communication LCPXPRESSO with mbed

785 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Da__X on Tue Nov 27 17:49:42 MST 2012
Hi!

I am trying to use my lpcxpresso 1769 (master) to communicate with my mbed lpc1768 (slave) board.

I used the spi_ssp example and I made only small changes in main.c

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include "lpc17xx_ssp.h"

#define SSP_CHANNEL LPC_SSP1
#define PORT_CSLPC_GPIO2
#define PIN_MASK_CS (1<<2)


int main(void)
{

SSP_CFG_Type sspChannelConfig;
SSP_DATA_SETUP_Type sspDataConfig;


PORT_CS->FIOSET |= PIN_MASK_CS; //CS High

uint8_t rxBuff[5];
uint8_t txBuff[5];

LPC_PINCON->PINSEL0 |= 0x2<<14; //SCK1
LPC_PINCON->PINSEL0 |= 0x2<<18;//MOSI1
PORT_CS->FIODIR |= 1<<2;//P2.2 as CSn

sspDataConfig.length = 1;
sspDataConfig.tx_data = txBuff;
sspDataConfig.rx_data = rxBuff;

SSP_ConfigStructInit(&sspChannelConfig);
SSP_Init(SSP_CHANNEL, &sspChannelConfig);
SSP_Cmd(SSP_CHANNEL, ENABLE);

int send = 3;

while(1)
{

PORT_CS->FIOCLR |= PIN_MASK_CS;//CS low
txBuff[0] = send;

//SSP_SendData(SSP_CHANNEL, send);
SSP_ReadWrite(SSP_CHANNEL, &sspDataConfig, SSP_TRANSFER_POLLING);


PORT_CS->FIOSET |= PIN_MASK_CS; //CS High
}
return 0 ;
}



It's actually very simple, I am sending the number 3 to the slave and I expect the slave to reply 1 (the first time) and with 8 all the next times. I can see that I receive the number 3 on my slave. But I don't receive any reply on my LPCXPRESSO....when I use the debbuger, I can see that I am always receiving 0.

Thats the code on my mbed board (example code for spi)

// Reply to a SPI master as slave

 #include "mbed.h"

 SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
 Serial pc(USBTX, USBRX);

 int main() {
     int u = 8;
     device.reply(0x01);              // Prime SPI with first reply
     while(1) {
         if(device.receive()) {
             int v = device.read();   // Read byte from master
             pc.printf("received: %d\n", v);
             //v = 3;
             device.reply(u);         // Make this the next reply
         }
     }
 }


I have no idea why I am not able to receive any messages from the slave.

I hope somebody can help me
0 Kudos
Reply
1 Reply

650 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Da__X on Wed Nov 28 05:19:52 MST 2012
Solved.

I forgot to set the MISO Pin.

LPC_PINCON->PINSEL0 |=((1 <<17)|(0<<16)); //MISO1


Cheers
0 Kudos
Reply