|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
PIC24: What can make spi_xfer() hang? |
Posted: Wed Mar 22, 2023 8:33 am |
|
|
Some code I am looking at, which was working fine half an hour ago, has started hanging. Using printf and then the debugger to verify, it is hanging at a spi_xfer() that was working fine earlier:
Quote: | spi_xfer (ADS8353_SPI_STREAM_MODE1, 0, 48); Code: |
The only thing that has changed is enabling debugging so I could use printf() and test this driver code. (This is existing code that is running in production and has been for over a year.)
Can the spi_xxx() calls block? I know I2C can hang, but I didn't think SPI could?
Thanks, much. |
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9189 Location: Greensville,Ontario
|
|
Posted: Wed Mar 22, 2023 8:38 am |
|
|
Obvious things, you've probably thought of...
Any chance the ADS8385 has become 'defective' ?
PCB trace is cracked ?
Power to ADS8385 has failed ?
The PIC24 has overheated ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Mar 22, 2023 8:43 am |
|
|
temtronic wrote: | obvious things, you've probably thought of...
any chance the ADS8385 has become 'defective' ?
PCB trace is cracked ?
power to ADS8385 has failed ?
The PIC24 has overheated ? |
This was not obvious to me, but now is something else for me to check. This is a fresh board I only hooked up a few days ago. I went through verification steps (it's an RF board with four RF outputs, and eight RF inputs) with signal generators and power meters and all worked fine.
This morning, I added some code to print the raw ADC values I am reading from this SPI driver (outside of the driver code, printing what the driver "read" returns) and it was working ... until it stopped.
With I2C devices, I can use ACK/NAK response to see if the part is there. To do that on this SPI device, we read a configuration register. It's hanging on that, but I would expect it to return 0 if there was no response to the clock pulses.
I'll stick production firmware back on it and see if it's still working. If it is, then I'll mark this up as a "strange compiler thing" and contact CCS support.
Thanks! _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9189 Location: Greensville,Ontario
|
|
Posted: Wed Mar 22, 2023 11:13 am |
|
|
hmm with SPI,
if the data line was low, yes, you'd get 8 zeros
but
if data was high, wouldn't you get 8 ones ??
never really thought about it until your post....
'fresh' board.. maybe there's an open between ADC and SPI data connection? Something you can't see except with a microscope?
I got bit decades ago. One remote board (of 240+) went 'odd'. Good one swapped out, bad came home. It was fine...then 'funny'....The slight flexing of the PCB finally showed I'd not soldered the wiper of a pot. Old school dbl sided, plated thru holes ,DIPs....2 seconds of soldering FIXED the issue.
I think today's PCB have less copper on them so might be prone to 'flex and break' ??
At least it's one more thing to see, then check it off the list.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19412
|
|
Posted: Wed Mar 22, 2023 11:48 am |
|
|
The only thing that can normally hang an spi_xfer on a PIC24, is that
something is holding the clock line. On the PIC24, the same clock, that
is sent, is also used to clock the input. So if the line is shorted the
spi_xfer will hang, because nothing clocks the input shift register. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Apr 17, 2023 11:32 am |
|
|
Ttelmah wrote: | The only thing that can normally hang an spi_xfer on a PIC24, is that
something is holding the clock line. On the PIC24, the same clock, that
is sent, is also used to clock the input. So if the line is shorted the
spi_xfer will hang, because nothing clocks the input shift register. |
I did not realize a SPI transfer could block. The issue "just went away" but I'm expecting it to pop back up when it is least convenient. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19412
|
|
Posted: Wed Apr 19, 2023 1:29 am |
|
|
Normally it can't.
However as I said, the one thing that can make it hang, is the clock.
On most of the later PIC's, the clock is fed out on a pin, and that signal
is fed back _from the pin_, to the input shift register. So what
can happen, is if this signal is shorted, the input register doesn't receive
a clock. Result, the input transfer doesn't happen. Hang.....
Obviously you can get this two ways. First a physical problem external
to the chip. Second the peripheral has got a configuration problem. For
example the PPS has got misconfigured on this pin, or the peripheral
itself has hung.
On my own code, at boot, I test before connecting the SPI, that the
clock pin can be raised and lowered. If it can't, there is an error message.
Otherwise the PPS and SPI is all setup.
The chip will watchdog, if there is an SPI hang, so if there is an external
problem the error message will then be displayed. If it was just a peripheral
problem, this will be cleared by the new setup. |
|
|
|
|
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
|