Data written SSPBUF whilst MSSP is active

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
picchiedi
Professional User
Posts: 142
Joined: Thu 2014-12-25 9:32

Data written SSPBUF whilst MSSP is active

Post by picchiedi »

Hello.

Running the enclosed project I have following error message, as soon I enter in each Print command of the While cycle:

[PIC18 MSSP] PC=0x05CE. Data written SSPBUF whilst MSSP (in master mode) is active - data has been ignored. [U3]

If I exclude the Part of program related to MCP3204 SPI, I have no error.
I don't understand, because looking at the oscilloscope signals, when Print is enabled, the MCP3204 signals are already ended, so they should not interfere.

Thank you for any suggestion.

Regards
Attachments
SPI_EADOG and MCP3204.zip
(34.94 KiB) Downloaded 42 times
Ettore
Labcenter Staff
Posts: 2932
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Data written SSPBUF whilst MSSP is active

Post by Ettore »

There is some sort of conflict somewhere the GLCD and MCP3204 routines that share the same SPI hardware registers.
If you comment out the line 'Print At 2,1, Dec1 voltage' - which hooks the GLCD include library - then you'll get MCP3204 to work with no warnings.
Conversely, if you comment out the lines that handle MCP3204 then the GLCD will be written with no warnings.

You have a number of options here, I think:

1) if you're willing then you may modify the GLCD include library to identify and remove the conflict.
2) Choose a different PIC18 variant with two hardware SPIs. For example the PIC18F45K22 is one that does for you.
3) Handle the MCP3204 with software SPI. Some of a bit bang technique is easy to implement and will do.

Anyway whatever you choose, there are a couple of oddities in the code handling the MCP3204, though is not the reason of the conflict.

The first one is the line SSPBUF = 1 << 6. Given voltage to CH0, I think you would write SSPBUF = 1 << 5 if CH0, single ended channel, had to be selected.

The second is the line wMCP_Adres=wMCP_Adres>>3. I'm not sure why is this there as given that the reference voltage is 4.096 then the 12-bit binary conversion of 2.5V at CH0 is 2500 (0x09C4). Such the binary value handled by the line 'voltage=(wMCP_Adres/4096)*4.096' gives exactly 2.5, which is what you were expecting of ?

If you comment the line wMCP_Adres=wMCP_Adres>>3 then you get the GLCD printing 2.5 even though with warnings and some garbage at the end, but this as I said is due to SPI conflict.

Hope it helps.
Kind regards,
Ettore Arena - Labcenter Electronics.
picchiedi
Professional User
Posts: 142
Joined: Thu 2014-12-25 9:32

Re: Data written SSPBUF whilst MSSP is active

Post by picchiedi »

Thanks a lot, Ettore, for your kind support and work (on Saturday too…)!

I knew that code for MCP3204 was not good (I took a MAX147 code as basis, but I didn’t updated for the moment since it was not my concern, about the problem).

I came out of the error and the print issue, by simply changing :
'SSPCON1=%00000010
SSPCON1=%00000000 ' clock FOSC/4

Enclosed the revised code and Proteus simulation (think now works properly).

I also found on google a thread with similar error “CCS___Viewtopic-interfacing pic16f877 with eeprom 25lc640” where you (think it were you, in 2012) solved it acting on optimization of the asm part of the code. Don’t know if applicable also in my case.

By the way, I don’t think Proteus is bad, as some people said in that thread. On the contrary I think Proteus is simple and excellent with an excellent support, particularly by you.

Many thanks again, Ettore, for the SPI variant handling suggestions too.

Regards
Attachments
SPI_EADOG and MCP3204_rev1.zip
(102.17 KiB) Downloaded 40 times
Post Reply