|
|
View previous topic :: View next topic |
Author |
Message |
SparkyEE
Joined: 15 Jun 2007 Posts: 7
|
hardware SPI read pin stuck |
Posted: Mon Jul 16, 2007 4:15 pm |
|
|
I have some code that executes SPI commands based upon user input from the UART (so I can peek and poke at a SPI device from Windows Hyperterm). The problem is that reads always read "FF". Looking at it on an oscope, shows that it is indeed reading 0xFF. Now I disconnect the SDI pin on the PIC from the target device and look again. The target device is indeed spitting out correct data on its SDO. For some reason, the PIC SDI pin is holding that line high... might it be set to an output? I'm using spi_read() and spi_write() commands later on in the code. They appear to work fine, but the SDI on the PIC is held high when it should be an input. Please reference the code fragment below of my setup.. Thanks.
I'm using a 16F887 on a PICkit2 USB debugger board. RC3=SCK, RC4=SDI, RC5=SDO.
Code: | #if defined(__PCB__)
#include <16C56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(internal=8)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
#elif defined(__PCM__)
#include <16F887.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(internal=8M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(internal=8)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
#use spi(MASTER, MODE=1, FORCE_HW, BAUD=1000000, BITS=8, stream=SPI_STREAM)
#use STANDARD_IO(B)
#include <input.c>
...
void read() {
BYTE address;
BYTE value;
printf("\r\nAddress 0x");
address = gethex(); // get address from user
address = address & 0x7F; // mask unused bits, boil down to address
address = address | 0x80; // set READ bit
output_bit(PIN_B0,0); // assert CSB low
spi_write(address); // write instruction byte
value=spi_read(0);
output_bit(PIN_B0,1); // deassert CSB high
printf (" = 0x%2x \r",value);
;
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 16, 2007 4:34 pm |
|
|
1. Are there two PIC boards, with one configured as an SPI slave and
the other as an SPI master ?
2. Post the list of connections between pins on the Master and on the Slave.
3. What's your compiler version ? |
|
|
SparkyEE
Joined: 15 Jun 2007 Posts: 7
|
|
Posted: Tue Jul 17, 2007 7:06 am |
|
|
PCM programmer wrote: | 1. Are there two PIC boards, with one configured as an SPI slave and
the other as an SPI master ?
2. Post the list of connections between pins on the Master and on the Slave.
3. What's your compiler version ? |
1 = The PIC as the master, and an Analog Devices DAC as the slave.
2 = List of connections (PIC --> slave): SCK-->SCK, SDO-->SDI, SDI-->SDO, GPIO{Pin_B0}-->CSB.
3 = compiler version is PCM 4.020b
Just to reiterate, SPI transmissions work, reading SPI works too
if I remove the PIC SDI line, I can see the slave SDO line working (I confirm it works through a logic analyzer). Its just that the PIC SDI line {Pin_C4} is not acting as an input and holds the slave SDO line high.
Thank you. |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Tue Jul 17, 2007 9:35 am |
|
|
I don't see a setup_spi() in your code, and I'm not sure, but maybe this is needed?
Ken |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jul 17, 2007 10:38 am |
|
|
Try upgrading, v4.020 wasn't a stable release and at least 20 releases have followed since then...
If I'm not mistaken v4.020b means you are using the demo version. To get a more recent version just download the demo version again from the website. |
|
|
SparkyEE
Joined: 15 Jun 2007 Posts: 7
|
|
Posted: Wed Jul 18, 2007 3:50 pm |
|
|
I don't believe setup_spi() is needed since I have a static configuration that does not need to be setup at runtime... although, I will try it.. It can't hurt.
I downloaded the latest CCS demo 4.043d and installed it per the suggestion above. I tried to compile my code (which compiled fine under 4.040b) and I get an error in the .h file:
Error 24 "C:\PROGRA~1\PICC\devices\16F887.h" Line 2(9,18): Unknown device type. Its erroring on the #device PIC16F887 line. What am I missing? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|