Transfering DATA between two pics via SPI OSHONSOFT

Status
Not open for further replies.
Is this from the master?
You have not set TRISCD for SDO in the slave.
Hi J,
Yes, from the MASTER
If you revisit #25 SLAVE I have clarified the comments, you should see that SDO is set correctly.
C.
 
Hi J,
Yes, from the MASTER
If you revisit #25 SLAVE I have clarified the comments, you should see that SDO is set correctly.
C.
The Define SPI... override the TRIS's and now:
Trisc.6 = 0 should be input
Trisd.3 = 0 should be input
Trisd.1 = 0
Trisd.2 = 1
Remove all Spi defines and SpiPrepare from the slave program!
 
Last edited:
The Define SPI... override the TRIS's and now:
Trisc.6 = 0 should be input
Trisd.3 = 0 should be input
Trisd.1 = 0
Trisd.2 = 1
Remove all Spi defines and SpiPrepare from the slave program!
Hi J,
True this is how SLAVE is set.
I have mild dyslexia, and no matter how many times I check, I see the settings as correct.

Here they are again.
NOTE (') = Commented out, so not in the program.

Perhaps, you could edit the program and I'll try your settings.

C
 

Attachments

  • 18F4431 8MHz INT JTEST 050219 1200.bas
    2.1 KB · Views: 314
Remove also SPIPrepare.
The Tris's look now ok in the program #43
Check the hw pins in portc and portd.
 
Last edited:
The way I remember TRISS settings is that 1 looks like I (start of Input) and so I know that setting TRISS to 1 makes it an input. You seem to be setting pins to 0 for an input.

Mike.
 
Hi J and M,
I'm not sure what I'm doing regarding INs and OUTs, but I always think I'm putting 1=IN and 0=OUT.

Anyway, here's the result of the test. [HSEROUT from the MASTER] READ on a Terminal]
C.
 

Attachments

  • 1234567890.jpg
    27.7 KB · Views: 319
Last edited:
Hi J and M,
I'm not sure what I'm doing regarding INs and OUTs, but I always think I'm putting 1=IN and 0=OUT.

Anyway, here's the result of the test. [HSEROUT from the MASTER] READ on a Terminal]
C.
Ok, the master and slave are working!
The ins and outs were correct in the Tris's, but the define SPI's messed them.
Now to read the 16bit azimuth, write azimuth.HB to SSBUF,
read it in the master, then azimuth. LB
Some conversation between master and slave is needed for this.
For example master could send 1 and when slave reads 1 it puts the highbyte into SSBUF, master reads it and then the same with 2 and the lowbyte
 
Last edited:
Hi J,
These tests are only between 18F4620 and 18F4431 when I put them into the bigger program with more SLAVEs, there needs to be a C/S for the AZIMUTH SLAVE (18F4431)

Perhaps I'll try one BYTE first. LB

NOTE: In tests I edited out SSPCON. Should it be in?
C.
 
Last edited:
SSPCON is needed in the slave program.
 
Hi J,
I've tried various variations, of what you suggest, but so far only 1x BYTE received.

MASTER:
If I SPISEND a number (BYTE) to the slave, so the SLAVE can act accordingly, then SPIRECEIVE 'say' AZIMUTHLB I get the number not the expected AZIMUTHLB. This is puzzling. (Can you explain how your test #24 works please.)

C.
 
In the slave read the SSPBUF until you get the number
( for example 1) then write the azi. LB into SSPBUF.
Something like this.
It reads the azi.lb once a second.

Code:
' In the master:
loop:
  spisend 1    ' I dont know  if 1 should be a variable with a value 1
  waitus 100 ' wait for the slave to act
  spireceive azi.lb
  hserout #azi.lb,crlf
  waitms 1000
goto loop

'In the slave
loop:
' get the azi.lb from QEI here
  d= SSPBUF
  if d=1 then
    SSBUF=azi.lb
  else
    goto loop
  endif
 
Hi j,
Will you explain what actually happens in your CODE in #24 please?
C.
It is a simple program to test that the data transfers between master and slave.
The master sends the numbers from 1 to 10 to slave and reads them back from the slave. The numbers coming back are shown on the terminal.
 
Hi J,
following #52: Because I always seem to receive a 1 if I SPISEND 1, I used a VARIABLE (LBHB) I also avoided 1, as I could RECEIVE 1 as a COUNT, so I chose 5 for LB and 7 for HB.

Using this:
SLAVE:
get_count:
WaitMs 1000
Toggle rled
''If SSPSTAT.BF = 1 Then

lbhb = SSPBUF
If lbhb = 5 Then
SSPBUF = azi.LB
Else
Goto loop
Endif

Hserout "SSPBUF=", #SSPBUF, " ", "AZI.LB", #azi.LB, CrLf

Goto get_count

AND MASTER:

EDIT:
Dim azi As Word
Dim lbhb As Byte
lbhb = 5



SPICSOn
SPISend lbhb
WaitMs 100
SPIReceive azi.LB
Hserout "AZI.LB ", #azi.LB, CrLf
WaitMs 1000
'azim = 1 'CHIP SELECT slave OFF
SPICSOff

I got this
C.
 

Attachments

  • LBHB.jpg
    52.7 KB · Views: 315
Last edited:
It is a simple program to test that the data transfers between master and slave.
The master sends the numbers from 1 to 10 to slave and reads them back from the slave. The numbers coming back are shown on the terminal.
Hi j,
So far I think I have only received whatever is sent to the SLAVE, but no actual information from the SLAVE.
Thanks, C.
 
I can't follow the logic.

You have goto loop, but no label loop.
The master sends lbhb, but its value is unknown.
Show both programs, master and slave.
 
I can't follow the logic.

You have goto loop, but no label loop.
The master sends lbhb, but its value is unknown.
Show both programs, master and slave.
Hi J,
Here is the full SLAVE program: (attached)

The MASTER is a section of a long program (I'll post it if asked)
Here:
_________________________________________________________________________________________
Dim azi As Word
Dim lbhb As Byte
lbhb = 5

main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
rled = 1
WaitMs 1000
rled = 0

'READ DATA from AZIMUTH (4431)

SPICSOn
SPISend lbhb
WaitMs 100
SPIReceive azi.LB
Hserout "AZI.LB ", #azi.LB, CrLf
WaitMs 1000
'azim = 1 'CHIP SELECT slave OFF
SPICSOff

'Hserout "AZIMUTH=", #azimuth, " ", "AZIMUTH.LB=", #azimuth.LB, " ", "AZIMUTH.HB=", #azimuth.HB, CrLf

goto main
_____________________________________________________________________________________
 

Attachments

  • 18F4431 8MHz INT COUNT 0_359 SPI 060219 1200.bas
    2.4 KB · Views: 290
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…