MASTER and SLAVE PICs using SPI in Oshonsoft

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
I'm ready to concentrate on this thread till resolved now.

To recall: I have 2x PICs on a PCB.
An 18F4431 with 2x BYTES of DATA [ 0-359 DEG ] which needs to be sent to an 18F4620 MAIN PIC via SPI.

The PICs are wired as SPI, with a separate track as a CS if needed.

I've been looking through the thread, and see that 'J2 ' has made a lot of effort, thanks for that, but I can't remember why I couldn't get it to work.

Here is a bit of CODE from ' E ' many moons ago:
I'm not sure if it can be used along side the already programmed way SPI is being used in my programs.

Can anyone point me which way is best please?
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
I'm trying different suggested CODE ans so far failing to get it any work in the MAIN program.

Looking at DATA SHEETS, I see there is a SLAVE SELECT PIN. Having seen this a long time ago, I added a track between the 2xPICs for this purpose.

While compiling the the SLAVE PIC 18F4431 program, I see this warning in the MPLAB IPE:
Here's the program:

C.
 

Attachments

ericgibbs

Joined Jan 29, 2010
21,460
hi C,
The Error msg is saying that the program is trying use Flash Program or RAM memory locations which do not exist on the 18F4431.
Post a copy of the *.lst file which Oshonsoft created when compiling the suspect code, it may give a clue where the problem is located.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
The Error msg is saying that the program is trying use Flash Program or RAM memory locations which do not exist on the 18F4431.
Post a copy of the *.lst file which Oshonsoft created when compiling the suspect code, it may give a clue where the problem is located.
E
Hi E,
I did the old 'Turn it OFF and turn it back ON' routine, and it has cleared, perhaps a typo?
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Previously in this thread there is CODE showing how to set up SSPCON and SSPSTAT, but I notice in one program it changes in the middle, where I'm fairly sure for what I want setting up SPI MASTER and SLAVE, the settings don't change.

I've tried setting up as I read the D/S, but haven't got it to work yet. Does anyone have the settings for these two PICs, especially in Oshonsoft, please?

EDIT: I've been reading through this thread, and it's really frustrating for me and I bet for the contributors too. There's information flying all over the place.

I don't know how to trouble shoots the programs, I have.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Looking at both of the PIC data sheets, I noticed MSSP. Is this making things more complicated than what's already been said above? MSSP, definately looks complicated to set up!

There seems to be too many choices for doing the same thing: Hardware, software, SPI, MSSP, bitbanging,. One post says don't use SPI, another says use it. How do I choose?
C.
 
Last edited:

jjw

Joined Dec 24, 2013
823
Oshonsoft BASIC SPI commands are only for the master and are implemented in software ( bitbanging)
The slave must be configured by setting SSPCON and SSPSTA.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Oshonsoft BASIC SPI commands are only for the master and are implemented in software ( bitbanging)
The slave must be configured by setting SSPCON and SSPSTA.
Hi J, EDIT: SLAVE
To clarify, I presume you mean SSPSTAT? I notice there's a question about CKP, that I don't know.

Does this look ok?

C
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi C.
If you recall, we used the hardware SPI commands way back on the displays, copy that method.
E
Hi E,
EDIT: I didn't join in on that thread, although I may have asked the initial question. I have some of those screen, so I will come back to your program, once I can concentrate on it better, thanks.
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,460
hi C,
This is a clip from an earlier prog, search your older files.
E

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc

EDIT: added a full listing, do copy/paste as required, it shows the method.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
This is a clip from an earlier prog, search your older files.
E

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc
Hi E,
Thanks.
I notice SSPCON1 uses NO SS CONTROL, I have an SS track on the PCB.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
This is a clip from an earlier prog, search your older files.
E

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc

EDIT: added a full listing, do copy/paste as required, it shows the method.
Hi E,
I looked through the program, but I couldn't follow it, as there are many settings for other than SPI, sorry. If possible I need an ABC of SPI transfer, that I can understand.
C.
 

ericgibbs

Joined Jan 29, 2010
21,460
hi,
These are the basic routines.
E

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc

Proc writecmd(hi As Byte, lo As Byte)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = hi
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = lo
While Not SSPSTAT.BF
Wend
ss = 1
End Proc

Proc writereg(addr As Word, data As Word)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = addr.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = addr.LB
While Not SSPSTAT.BF
Wend
ss = 1

'write data
lcd_mode = 1
ss = 0
spi8 = SSPBUF
SSPBUF = data.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = data.LB
While Not SSPSTAT.BF
Wend
ss = 1
End Proc
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi,
These are the basic routines.
E

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc

Proc writecmd(hi As Byte, lo As Byte)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = hi
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = lo
While Not SSPSTAT.BF
Wend
ss = 1
End Proc

Proc writereg(addr As Word, data As Word)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = addr.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = addr.LB
While Not SSPSTAT.BF
Wend
ss = 1

'write data
lcd_mode = 1
ss = 0
spi8 = SSPBUF
SSPBUF = data.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = data.LB
While Not SSPSTAT.BF
Wend
ss = 1
End Proc
Hi E,
To clarify: TRANSMITTER (18F4620 MASTER)
I only see WRITE in this CODE, where I want to READ/RECEIVE DATA from the SLAVE 18F4431, which has the INCREMENTAL ENCODER connected.

I attached CODE for the SLAVE above in #191 is this correct? (It shows the correct READings from the HSEROUT in the computer TERMINAL Teraterm)

Below I notice that SSPCON is commented out and includes
no SS control There are [ SS=0 ] is this correct?
Thanks, C.


Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc

Proc writecmd(hi As Byte, lo As Byte)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = hi
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = lo
While Not SSPSTAT.BF
Wend
ss = 1
End Proc

Proc writereg(addr As Word, data As Word)'write addr to reg
lcd_mode = 0
ss = 0
spi8 = SSPBUF
SSPBUF = addr.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = addr.LB
While Not SSPSTAT.BF
Wend
ss = 1

'write data
lcd_mode = 1
ss = 0
spi8 = SSPBUF
SSPBUF = data.HB
While Not SSPSTAT.BF
Wend
spi8 = SSPBUF
SSPBUF = data.LB
While Not SSPSTAT.BF
Wend
ss = 1
End Proc
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi E,
Interesting video.
I notice that I need to add a pull up on the SS track.

In the video at 8mins regarding BITS 6 and 7, it wasn't clear how to set them for MASTER SLAVE, especially CKE
Otherwise I think I have all of the settings as the video.
Thanks.
C.
 
Top