Using GPIO for SPI CS

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

Using GPIO for SPI CS

1,085 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dubbie on Sat Jul 05 18:48:00 MST 2014
Hi,

I am working with a chip that sends up to 32bit ints

I have managed to talk to it using 16bit frames like the datasheet shows. However, the datasheet specifies that the CS must be held low while the instruction to retrieve the CNTR register is issued (an 8bit intstruction) and then kept low while the rest of the bits come in.

I get the first 8 bits because they come immediately after the read instruction is sent, but as soon as the CS goes high, the chip stops sending data. Even though I send zeros immediately after, no more data arrives.

It seems to me that I need to use a GPIO pin to "roll my own" CS line. My question is, I have no idea how to time this. Any suggestions are very welcome.

This is the datasheet. Page 8 shows the relevant diagram
http://www.usdigital.com/assets/general/LS7366R.pdf

I have also attached a screenshot from my scope for a read operation.

Here is my code I am using to read the register

Chip_SSP_Int_FlushData(LPC_SSP);
uint16_t ntx_data;
ntx_data = (0x6000); // instruction read the CNTR register 0110 0000 0000 0000
Chip_SSP_SendFrame(LPC_SSP, ntx_data);
ntx_data = (0x0000); // send nothing to keep the clock going
Chip_SSP_SendFrame(LPC_SSP, ntx_data);


uint16_t rxedData = Chip_SSP_ReceiveFrame(LPC_SSP); // get first frame
uint16_t rxedData2 = Chip_SSP_ReceiveFrame(LPC_SSP); // get second frame



I am using LPCOpen with LPCXpresso on an LPC1347Xpresso dev board
0 Kudos
6 Replies

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rorrik on Wed Jul 16 12:58:32 MST 2014
These questions might be really naive, but choose a gpio line? I'm really just having trouble sifting through this SPI example. Do you have a good resource for learning the libraries and things?
0 Kudos

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dubbie on Wed Jul 16 12:24:53 MST 2014
Just ignore the "official" SS line. Choose a gpio line and wire that up instead. Then you can just control that like any other gpio pin.
0 Kudos

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rorrik on Wed Jul 16 08:18:47 MST 2014
Can you elaborate on how to set CS high manually, as opposed to automatically? Thanks.
0 Kudos

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dubbie on Sun Jul 06 02:21:33 MST 2014
Thanks very much for your suggestions.

This worked!

0 Kudos

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Jul 05 23:22:20 MST 2014
1) Put CS to low (manually, not automatically by SPI peripheral)
2) Send one byte via SPI
3) Check if byte was sent on SPI
4) Check if a byte was received on SPI
5) Receive it
6) Repeat steps 2 to 5 as often as you want
7) Put CS to high (manually, not automatically by SPI peripheral)

0 Kudos

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dubbie on Sat Jul 05 23:09:22 MST 2014
As an update,

For now I have added a:

while (Chip_SSP_GetStatus(LPC_SSP, SSP_STAT_BSY)) {}


between each GPIO CS pin set.

This is blocking, but for now I guess it will have to do!
0 Kudos