MASTER and SLAVE PICs using SPI in Oshonsoft

ericgibbs

Joined Jan 29, 2010
21,463
hi C.
Recapping,
the Master uses the 'ss' line pulled low, to alert the Slave that it going to send data, while it is sending that data Bit by Bit, so is the Slave is send what in its SSBUF to the Master.
So 'ss' PORTA.4 on the Master is set as an Output, on the Slave its set as Input.

Is there instance in your project when the Slave has data that it wants send to the Master.? and it cannot wait to be Polled by the Master.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C.
Recapping,
the Master uses the 'ss' line pulled low, to alert the Slave that it going to send data, while it is sending that data Bit by Bit, so is the Slave is send what in its SSBUF to the Master.
So 'ss' PORTA.4 on the Master is set as an Output, on the Slave its set as Input.

Is there instance in your project when the Slave has data that it wants send to the Master.? and it cannot wait to be Polled by the Master.

E
Hi E,
Yes, your recap all understood, and as programmed.

For these tests, I've got a simple number, so that I will see it if it ever gets sent from SLAVE to MASTER, but in the project itself, the DATA would sit in SLAVE till MASTER called for it.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
In the slave you have ss=1??
I don't know what happens when input pin is written from "inside", but it is wrong anyway.
ss should be controlled by the master
Hi J,
I've had a rethink about SS= 1

Does the SLAVE need to READ the SS PIN within the [ xfer_slave ] LOOP?
C
 

ericgibbs

Joined Jan 29, 2010
21,463
hi C,
Looked thru loads of data, it looks as though it could be an error.???
All the 18F4431 read as PORTC,, check the Micrchip for any Errata publications
E
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
Looked thru loads of data, it looks as though it could be an error.???
All the 18F4431 read as PORTC,, check the Micrchip for any Errata publications
E
Hi E,
I checked the erratas, and didn't find anything, so let treat it as an error for now, thanks.
C.
 
Hi,
Here are the latest programs:
At the moment, I am only testing for transfer of DATA between the 2xPICs, using a digital analyser, connected on the tracks between them.

Looking at the SLAVE 4431 Program, Some of the comments in the guide at #208, don't correspond to the D/S. Can someone verify please? (Marked ^^^^^^^??????????)

EDIT: The none flashing SLAVE LED is now flashing [ START UP LED ] (Something to do with TRIS set-up) but not in the LOOP. I think this tells me that the PIC is working, but it is not LOOPing the [ xfer_slave ]
EDIT
C.
I am not an expert and do not know your programming software so please treat this with caution.
on the 4331 listing:
I assume the Define CONFIGXX statements are defining the CONFIGax/bx/cx/dx etc registers on the microchip datasheet.
The comments in the symbol section do not appear to relate to the target device.
The start up LED section appears to be inline code so will only operate once. I assume that it needs a label such as "Toggle led:"
I am not sure what is happening at ' 'ADCON1. The double comment is confusing me. Have you got the right register for your data?
ss - an input is being written to with a 1
SSPSTAT.CKE - as this is a slave data should be read in the falling edge of SCK not transmitted.
Please feel free to flame me if I am talking rubbish
cc
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
I am not an expert and do not know your programming software so please treat this with caution.
on the 4331 listing:
I assume the Define CONFIGXX statements are defining the CONFIGax/bx/cx/dx etc registers on the microchip datasheet.
The comments in the symbol section do not appear to relate to the target device.
The start up LED section appears to be inline code so will only operate once. I assume that it needs a label such as "Toggle led:"
I am not sure what is happening at ' 'ADCON1. The double comment is confusing me. Have you got the right register for your data?
ss - an input is being written to with a 1
SSPSTAT.CKE - as this is a slave data should be read in the falling edge of SCK not transmitted.
Please feel free to flame me if I am talking rubbish
cc
Hi CC,
The word expert is used cautiously here, I've been trying to get this working for 6months.

The config settings are Oshonsoft settings as shown here, so not in the D/S,but in the OSH Help (I keep checking them!):

The comments next to the SYMBOL section are from when I copied the original. (Now removed)

I add 'start up leds' at the beginning of a program, so I can see the PIC is working. A also added a TOGGLE LED within the [ xfer_slave LOOP ] so I can see if the LOOP is working.

The ADCON1 settings are from the original, which I've left to remind me to re-check. I think this is the setting for the original PIC to set ALL DIGITAL, which I hope I have replaced correctly by ANSEL0.

The SSPSTAT.CKE setting is a REGISTER PIN setting, and in later programs this is in a 'Set-up' GOSUB.

Thanks,
C.

There was a previous question about [ SS=1 ] that wasn't answered. I'll bear it in mind. Previously, I have tested changing it to [ =0 ] and removed it. I think once the program gets to the LOOP, any [ SS ] change should be controlled by the MASTER.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi, TRANSMITTER

SLAVE:
Will someone look at [ LATD<1> ] in the D/S please?

I appears that for SPI all OUT PINS need to be set using LAT

I've tried using:

LATD.1 = 0
PORTD.2 = 1
PORTD.3 = 1

with or without using [ TRISD = %00001100 '6=led-7=led 3=SCKIN 2=SDI 1=SDO]
but this doesn't work.

I've also tried this type of thing:
Symbol dout = LATD.1
dout = 0
Which also fails.

Can someone tell me the best way to set the PINs for SPI, please?

EDIT:I think I've realised my error! LATD.1 makes the PIN DIGITAL, but as it is set for SPI then TRIS is used. Is this correct?
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,463
hi C,
The 18F4431 SS pin is not used to set the PIC as a Slave.
When the Master wants to to communicate with the Slave, it sets SS Low, this starts the Slave output data transmission to the Master and at the same time the Master sends data to the Slave.
SS is set High by the Master at the end of the data exchange cycle.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
The 18F4431 SS pin is not used to set the PIC as a Slave.
When the Master wants to to communicate with the Slave, it sets SS Low, this starts the Slave output data transmission to the Master and at the same time the Master sends data to the Slave.
SS is set High by the Master at the end of the data exchange cycle.
E
Hi E, TRANSMITTER
SLAVE:
I've set [ TRISC = %01000000 '6=SLAVE SS ]
that's all, is this correct?

There is:
[ Define SPI_CS_REG = PORTC
Define SPI_CS_BIT = 6 ]
in the D/S.
When would this be used? We aren't using it here!

Otherwise, I've tried all of the suggestions, plus many of my own, and no DATA travels from SLAVE to MASTER. Is it possible that OSH can't do it?
C.
 

jjw

Joined Dec 24, 2013
823
Define SPI... are used in Oshonsoft Basic for SPImaster.
Now you use hardware SPI.
Don't use DEFINE SPI...

You did not answer about pins you are using for SPI
Which pin numbers in the slave are: SPI clock, DI, DO
 

ericgibbs

Joined Jan 29, 2010
21,463
hi C,
I thought we had agreed the 18F4431 had a possible typo for PORTA,6, ie: should be PORTC.6

Reading thru the d/s,Section 10.3 I wonder if Osh has it covered, may be a bug.?

E

BTW: You can TRIS individual port bits eg: TRISC.6=1
 

Attachments

jjw

Joined Dec 24, 2013
823
Hi, TRANSMITTER

SLAVE:
Will someone look at [ LATD<1> ] in the D/S please?

I appears that for SPI all OUT PINS need to be set using LAT

I've tried using:

LATD.1 = 0
PORTD.2 = 1
PORTD.3 = 1

with or without using [ TRISD = %00001100 '6=led-7=led 3=SCKIN 2=SDI 1=SDO]
but this doesn't work.

I've also tried this type of thing:
Symbol dout = LATD.1
dout = 0
Which also fails.

Can someone tell me the best way to set the PINs for SPI, please?

EDIT:I think I've realised my error! LATD.1 makes the PIN DIGITAL, but as it is set for SPI then TRIS is used. Is this correct?
C
You must use TRISD to set the SPI pin directions for the Slave.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
I thought we had agreed the 18F4431 had a possible typo for PORTA,6, ie: should be PORTC.6

Reading thru the d/s,Section 10.3 I wonder if Osh has it covered, may be a bug.?

E

BTW: You can TRIS individual port bits eg: TRISC.6=1
Hi E,
Yes, as the program [ TRISC = %01000000 '6=SLAVE SS ]

I don't fully understand your images, as they aren't in BASIC, but I suspect that there may be a bug, although I can't be sure. Is there a way to test it?

When I was testing I tried both:
[ While SSPBUF = 0 and While SSPSTAT.BF = 0
Wend ] (Not at the same time:))
There is a LED in the LOOP, which flashes when [ SSPBUF = 0 ] is used, but doesn't flash when [ SSPSTAT.BF = 0 ] is used.
This tells me there is something in the [ SSPBUF ] but it isn't full.
Do you agree?
C
 
Last edited:
Top