Trying to read dipswitch through SPI to LCD

SC9

Newbie
Joined
May 11, 2024
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
44
Hi all,

I'm using PIC18F25K22 which is 8 bit system, SPI, MCP23S08.
A1 is set to 1 and A0 is set to 1 as well on the hardware.
The software used in Mplab – anscii – embedded c
I want the SPI supposed to be control a servo later on - but at the moment I have little faith that the SPI connection to PIC is working..
I'm trying to use LCD screen to show the state of dipswitches.

The LCD code works on it's own, but the dipswitch message always read 0, regardless of what I do to them.

The code is below I believe the issue is somewhere with the SPI and MCP configuration but I've been staring at it for the past week and I really can't see what I'm missing.

Any pointers would be appreciated!




 

Attachments

  • Dipswitch.txt
    6.8 KB · Views: 32

Hi,

I´ve used the MCP23S08. As input as well as output.

To give you detailed answer I need detailed informations first.
Like a schematic, especially the MCPxx part.

Do you have a scope to verify SPI signals?

Klaus
 

Hi,

I´ve used the MCP23S08. As input as well as output.

To give you detailed answer I need detailed informations first.
Like a schematic, especially the MCPxx part.

Do you have a scope to verify SPI signals?

Klaus
Hi,
Thank you for replying!
Unfortunately I have nothing to scope the SPI signals. I tried adding LED light - in case the issue is with my LCD but, no joy there.
The schematic can be seen below. A1 and A0 are set to 1 in the hardware.

 

in case the issue is with my LCD
So you don´t know whether the problem is SPI or display?.

Better give a detailed error description. How do you test it? What is your expectation? What does work like expected, what does not work like expeted?
And do your software debuggin step by step.

Klaus
 

I want to ensure that SPI link is working - the end goal is for the dipswitches to control the angle of the servo movement, which I attempted and didn't work so I tried to scale back what I was doing.

I checked dipswitches without SPI, with the connection to the PIC - I used LED and 7 segment signal and it worked fine.

The LCD turns on and I can send messages to it, but it won't count the dipswitches that have been flipped. I'm not sure whether the code for the LCD to do this is 100% correct though. That's why I added LED light in case the issue was with my LED 'counting' code.

I'm running out of the ideas how I can check whether it's definitely SPI link that is not working - but it seems that other components are working fine till the SPI is connected to it.

At this point, I think it's either hardware, or something in my code that has been done incorrectly. I have 2 MCPs on my board and I tried connecting to both, however that didn't change anything.. so I'm kind of leaning towards the code being an issue..

Thank you!
 

Well, i’m confused. How did you make the jump from ‘the display doesn’t show the state of the dip switches’ to ‘the SPI doesn’t work’?

Maybe it’s:
1. The MCP23S08.
2. A bad connection
3. Your code (sorry, i’m not going to read through all that)
4. Your display

Have you verified you can write ANYTHING to the display?
Have you tried using the debugger? That would be the first thing I did before posting anything.
 

Sorry, I'm most likely writing about it in roundabout way, as I'm pretty inexperienced with embbeded.

I think the SPI doesn't work -as whenever I wanted LCD or LED to react to dipswitches which are connected to MCP/SPI, nothing was happening. Yet, dipswitches work fine, when connected directly to PIC.

At this point I just want to ensure the MCP/SPI works. I think I initlised it correctly.

Yes, I can write to LCD no problem, there are no issues displaying messages. I'm using mplab icd 4 for debugging.

Thank you
 

Hi,

I recommend to first make the display work. Then you can use it as visual feedback for any other device/software debugging.

the data flow seems to be:
MCP --> SPI --> microcontroller (SPI byte) --> ASCII byte --> display

Now write software step by step in this (backwards) order

* Make the display work, just to show anything useful
* then make the display to an show ASCII variable (single byte), but continously changing. Like "0" then "1" and back with a delay of 1s
* then make a variable (maybe a counter, 1 s period time), generate 8 ASCII values "0"/"1" (according the bit states) and display them
* then read the SPI and value and display it

Report what happens, where you encounter problems.

Klaus
 


where you are storing the response from MC23S08 IC?
Try to do it like that and print it on LCD, what you receive from MC23S08
uint8_t WriteSPI(unsigned char data) {
SSP1BUF = data; // Write data to SSPBUF (data buffer)
while(!PIR1bits.SSPIF); // Wait for complete 1 byte transmission
PIR1bits.SSPIF = 0; // Clear SSPIF flag
return SSP1BUF;
}
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…