View previous topic :: View next topic |
Author |
Message |
hucker
Joined: 25 Jan 2017 Posts: 7
|
SPI Problem on port from 16f877 to 16f887 |
Posted: Thu Feb 16, 2017 2:10 pm |
|
|
I am porting a project when we did a board spin and am having issues getting the SPI code to work correctly. The legacy 877 code has been stable and running for many...many... years.
We have an SPI bus with two devices (like before), a programmable gain amplifier/MUX (MCP6S28) and an A/D (MCP3208).
The new layout is the same as the old layout in terms of pins on the 887 and the two SPI devices.
When I watch the signals on the scope I see the command go out on the SPI, I see the PGA/Mux receive the command and a new analog voltage show up at the AD, I see the chip selects change and the AD clocks out the data however the spi_read always returns 0x00.
I'm using this legacy setup (that has worked for years):
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);
and the following code to read the data (again legacy):
Code: |
int32 get_ad_value(int gain_ind,int channel)
{
unsigned int low,high;
int16 value;
set_pga(gain_ind,channel);
output_low(MONITOR_AD_SPI_CS);
// Always read channel 0
spi_read(0x6);
high = spi_read(0) & 0xf;
low = spi_read(0);
// commands to send
output_high(MONITOR_AD_SPI_CS);
value = make16(high,low);
return value;
} |
I have looked in the debugger and see that high/low both have 0x00 in them.
Apparently I have clock and MOSI setup correctly because I am seeing the two parts change state as expected, what I don't ever see is the PIC reading a number from the SPI.
I am now thinking there is some other setup or errata or other piece of information I'm missing. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Thu Feb 16, 2017 2:20 pm |
|
|
have you tried an 877 in place of the 887 in the new board? |
|
|
hucker
Joined: 25 Jan 2017 Posts: 7
|
|
Posted: Thu Feb 16, 2017 2:33 pm |
|
|
Nope... I probably need to order one but I have not tried that. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Thu Feb 16, 2017 2:47 pm |
|
|
I got 2 tubes full of them, 20 years old...sigh...
Be sure to install a socket so you can swap the PICs out.
Jay |
|
|
hucker
Joined: 25 Jan 2017 Posts: 7
|
|
Posted: Thu Feb 16, 2017 5:56 pm |
|
|
Rework had bad solder joint on the backside of the test point. Data looks good on testpoint...but not on MISO pin on 887. Argh |
|
|
|