SPI Master transmit problem on PIC18F46K22 via MSSP
Hey all, I think either I'm doing something braindead or something is wrong with the MSSP (I'd bet on the former but I really can't see what I'm doing wrong).
I've reduced the code down to about the smallest test case that I can easily verify still has the problem. I think something is going wrong in SerDriverTryPumpByte: - what is happening, is two bytes are being transmitted and then transmission stops (I am counting transmission by the dashes printed out to the debug port and captured via UART emulation mode on a PicKit2). It should be a continuous transmission of 16 bytes, then a manually triggered strobe on a sync signal, then transmission starts over (it is sending state to a serial driver board).
I guess I can't rule out some kind of side effect from the RS-232 ring buffer code but that code has already worked for other parts of the project and shouldn't be touching anything related to the MSSP.
All interrupts are turned off and the main loop is reduced to just pumping the RS-232 transmit for debugging feedback and the SPI transmit to test the problem.
Thanks in advance if anyone has ideas!
Posted May 7, 2015, 4:36 AM UTC
Update: Scoping the output, I see that one byte is actually being clocked out on the pins. Apparently write collision is occurring, but I don't understand how when I am checking for byte reception complete before moving the data.
So, I found some sample code that had an explicit check for failure of the MSSP to accept a byte, and then it cleared the write collision bit and tried transmission again.
This seems to work, and transmitted data looks right, but I don't think it is correct that the chip indicates a write collision. Could this be an unidentified errata?
ok, pages 216, 259 of the datasheet... bif BF from SSPxSTAT works only with the double byte buffer of the receiving part of the MSSP...
basically it will be set if you don't read SSPxBUF for 2 received bytes... but what you are trying is sending byte by byte right?
you need to work with the interrupt flag... mmm... SSPxIF from...PIR1 (or Pir3 for the 2nd mssp)
if you don't want to work with interrupts, you don't need to enable on the equivalent PIE registers, just check or wait until SSP1IF is set and then continue
mmaybe something like:
Update: My workaround wasn't really stable after more delay was put back in the main loop. I can't get it to work with SSP1IF either. It always wants to indicate write collision, and I'm not sure the output is correct when it is transmitting.
I may ignore the MSSP and bitbang the output - without resolving this it doesn't seem usable.
[Update 2]: bitbanging the output seems to work fine, and actually gets approximately the speed I wanted.
That's the thing, I had tried that first and didn't have any luck either. I'll give it another shot though!