friesen
Super Member
- Total Posts : 2169
- Reward points : 0
- Joined: 2008/05/08 05:23:35
- Location: Indiana, USA
- Status: offline
spi Chip select
I am attempting to read a mcp3208. I have a logic analyzer hooked up that shows no activity on the CS pin. Do I have to hand drive this? If so, what in the world is the RP setting and stuff for the CS pin?
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/20 19:50:51
(permalink)
SPI is a fairly difficult bus to deal with as you will see if you search these forums. Several posts topics on SPI CS and the problems have recently been posted here. And, perhaps the overview Microchip published here: http://ww1.microchip.com/downloads/en/DeviceDoc/spi.pdf Will get you started. But, yes you must select the slave using the CS pin before sending/receiving data. You may be able to permanently select the slave if you only have the PIC and one other device, e.g. a single mcp3208. CS is typically a digital output pin of your choice set low or high as needed.
|
friesen
Super Member
- Total Posts : 2169
- Reward points : 0
- Joined: 2008/05/08 05:23:35
- Location: Indiana, USA
- Status: offline
RE: spi Chip select
2009/05/20 19:53:49
(permalink)
I guess I should be more specific. I have set the correct rpor for my CS and also the trisbit. There is no activity on the CS pin.
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/20 20:05:51
(permalink)
In the spirit of being more specific, you must toggle CS up and down as needed before and after each communication. That’s how you determine which of multiple devices you are interfacing. Supposedly only the slave you selected via CS listens/talks on the bus.
|
friesen
Super Member
- Total Posts : 2169
- Reward points : 0
- Joined: 2008/05/08 05:23:35
- Location: Indiana, USA
- Status: offline
RE: spi Chip select
2009/05/20 20:11:18
(permalink)
Ok, what is the purpose of the selectable output sources (page 125 of the manual for the pic24f gb series) Output function 9? (ss1out - spi1 slave select output) in the rp output mapping
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/20 20:19:40
(permalink)
Got me. I have always used PIC 24H SPI and have not heard of this capability. But then, perhaps it’s just one more source of SPI problems.
|
friesen
Super Member
- Total Posts : 2169
- Reward points : 0
- Joined: 2008/05/08 05:23:35
- Location: Indiana, USA
- Status: offline
RE: spi Chip select
2009/05/20 20:23:24
(permalink)
I have been trying to create my own signal, and am unable to properly frame the CS signal for the 3208. What is a good start and stop sync? I have been trying this void InitMCP3208(void){ RPINR20bits.SDI1R=40;// set up rp pin 40 to DI RPOR10bits.RP21R=7;//set up rp21 to DO //RPOR13bits.RP26R=9;//set up rp26 to CS RPOR9bits.RP19R=8;//set up rp19 to CKS SPI1CON1=0b0000000101111010; SPI1CON2bits.SPIBEN=1;//enhanced buffer SPI1STATbits.SPIEN=1;//enable spi port SPI1STATbits.SISEL=0b101; //SPI1CON1bits.MSTEN=1;//Master mode TRISGbits.TRISG7=0; LATGbits.LATG7=1; SPI1CON1bits.PPRE=0b10;//clock div 4 = 2 mhz SPI1CON1bits.SPRE=0b111;//no secondary prescale SPI1STATbits.SPIROV=0;//clear overflow flag } int readchannel(char channel){ int reading; char command1,command2; //while(SPI1STATbits.SRMPT==0);//wait until previous is finished LATGbits.LATG7=0; command1=channel&0b111;//clear spurious request command1=command1>>2;//set for sending command1=command1 | 0b110;//add start and signal bit SPI1BUF=command1;//send on its way command2=channel&0b11;//clear spurious requestb command2=command2<<6;//set for sendind SPI1BUF=command2; SPI1BUF=0;//send empty request while(IFS0bits.SPI1IF==0);//wait until is finished reading=SPI1BUF;//read to clear first reading=SPI1BUF;//top byte reading=(reading<<8)+SPI1BUF;//bottom byte LATGbits.LATG7=1; IFS0bits.SPI1IF=0; reading=reading&0b111111111111; return reading; }
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/20 20:40:56
(permalink)
Ok, I looked at the spec and I believe that is the pin that is used as CS for the PIC24 if it is operating as a slave. In that case the master would toggle the specified pin when it wants to communicate with the PIC but then it's an input...
post edited by sequoia - 2009/05/20 20:44:54
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/20 21:42:24
(permalink)
|
friesen
Super Member
- Total Posts : 2169
- Reward points : 0
- Joined: 2008/05/08 05:23:35
- Location: Indiana, USA
- Status: offline
RE: spi Chip select
2009/05/21 04:02:48
(permalink)
I believe you are right sequoia about the cs being for framed mode. I find it frustrating that some of the pic24f reference manuals do not seem complete. Take the PMP for example. I think many become frustrated and bit bang it. I think I am going to bit bang this interface, as trying to place a correct CS signal on the free running SPI module seems harder than just bit banging out the bones basic interface of the 3208.
|
sequoia
Super Member
- Total Posts : 222
- Reward points : 0
- Joined: 2008/08/04 17:17:09
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/21 05:22:05
(permalink)
|
tom_g_robin
New Member
- Total Posts : 9
- Reward points : 0
- Joined: 2009/05/21 07:26:31
- Location: 0
- Status: offline
RE: spi Chip select
2009/05/21 08:23:39
(permalink)
Some where i found a program in which the programmer manually change CS as it requires as high or low according to the device. So i think that we have to control the CS pin for framed communication.
|