Hi,
For several days I'm trying to use the MSSP
The complete project is to use 4 x PIC18F45K22 as slave and another one as Master.
At this time I just simulate data between 1 slave and the master with Proteus 8 and... the simulation works.
Unfortunately, test with my PCB makes me crazy.
When Master asking to slave with a "?" I expect to receive "!WAY0625"

or HEX: 21 57 41 59 30 36 32 35
This is simulation give, but in fact (Real PCB) the slave never answer the good message beginning by "!"

don't care about the "41 hex" in place of "3F hex", this is because I'm trying other than "?" to begin TX.
The problem is: Why $10 on MISO (or other stupid values)
Here is my code:
Code:
'****************************************************************
'* Name : master.BAS *
'* Author : Herve Helleboid *
'* Notice : Copyright (c) 2013 HYTEM *
'* : All Rights Reserved *
'* Date : 02/11/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 64
TRISA = %00000000
TRISB = %00000000
TRISC = %10010000
TRISD = %10000000
TRISE = %00000000
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
ANSELD = %00000000
ANSELE = %00000000
' configuration USART2 (communication avec FAV)
RCSTA2 = $90 ' Enable serial port & continuous receive
TXSTA2 = $20 ' Enable transmit, BRGH = 0
SPBRG2 = 77 ' 9600 Baud @ 48MHz, 0,16%
' configuration USART1 (communication RS232 externe)
RCSTA1 = $90 ' Enable serial port & continuous receive
TXSTA1 = $20 ' Enable transmit, BRGH = 0
SPBRG1 = 103 ' 9600 Baud @ 64MHz, 0,16%
SSPEN VAR SSP1CON1.5 ' SSP Enable bit
CKP VAR SSP1CON1.4 ' Clock Polarity Select
SMP VAR SSP1STAT.7 ' Data input sample phase
CKE VAR SSP1STAT.6 ' Clock Edge Select bit
SSPIF VAR PIR1.3 ' SPI interrupt flag
SS0 var PORTB.3
SS1 VAR PORTB.1
SS2 VAR PORTC.2
SS3 VAR PORTC.1
LED VAR PORTE.0
slave var byte
i VAR BYTE ' loop counter
a VAR BYTE[6] ' Holds characters read from slave
HIGH SS0 'slaves are waiting (slave select pin)
HIGH SS1
HIGH SS2
HIGH SS3
HIGH LED
PAUSE 300
LOW LED
pause 300
hserout ["rdy",13,10]
SSP1CON1 = %00100010
SSPIF = 0 ' clear buffer full status
mainloop:
GoSub getdata ' initiate conversion and receive data
hserout ["lst ",STR a\7,13,10] ' display received string
high SS0
Pause 500
toggle led
GoTo mainloop ' do it forever
getdata:
low SS0
pauseus 10
SSPBUF = "?" ' send ? to start conversion
GOSUB letclear ' wait for buffer to clear
IF SSPBUF<>"!" Then getdata ' wait for reply (!)
For i = 0 to 6 ' loop for 7 characters
SSPBUF = 0 ' write to SSPBUF to start clock
GOSUB letclear ' wait for receipt
a[i] = SSPBUF ' store received character in array
Next i ' get next character
Return
letclear:
IF SSPIF = 0 Then letclear ' wait for SPI interupt flag 1=TRx complet must be cleared
PauseUs 25 ' 25uS fudge factor
SSPIF = 0 ' reset flag
Return
and
Code:
' Name : SPISLAVE.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' pic18f45k22 @ 16MHz PLLx4 = 64MHz
'
DEFINE OSC 64
TRISA = %00100000
TRISB = %00000000
TRISC = %10011000
TRISD = %10001000
TRISE = %00000000
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
ANSELD = %00001000
ANSELE = %00000000
' Allocate RAM
dataout VAR BYTE[8] ' Data out array
SSPEN VAR SSP1CON1.5 ' SSP Enable bit
CKP VAR SSP1CON1.4 ' Clock Polarity Select
SMP VAR SSP1STAT.7 ' Data input sample phase
CKE VAR SSP1STAT.6 ' Clock Edge Select bit
SSPIF VAR PIR1.3 ' interrupt flag - last bit set
i VAR BYTE ' loop counter
a VAR BYTE[6] ' Holds 6 characters of data
led var PORTA.4
way var byte 'n° de voie
' SSP1CON1 = %00000101 ' configure SPI slave, no SS
SSP1CON1 = %00000100 ' configure SPI slave with SS
CKP = 0 ' clock idle low
CKE = 0 ' transmit on idle to active transition
SSPIF = 0 ' clear SPI interrupt
SMP = 0 ' sample in middle of data
RCSTA1 = $90 ' Enable serial port & continuous receive
TXSTA1 = $20 ' Enable transmit, BRGH = 0
SPBRG1 = 25 ' 38400 Baud @ 64MHz, 0,16%
DEFINE ADC_BITS 8 ' ADCIN resolution (Bits)
DEFINE ADC_CLOCK 7 ' ADC clock source (Frc)
DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
dataout[0] = 87 ' Preset output WAY0625
dataout[1] = 65
dataout[2] = 89
dataout[3] = 48
dataout[4] = 54
dataout[5] = 50
dataout[6] = 53
HIGH LED
PAUSE 300
LOW LED
ADCIN 23,way
IF way < 30 then
way = 48 'way 0 for 470R
goto mainloop
endif
IF way < 60 then
way = 49 'way 1 for 2K2
goto mainloop
endif
IF way < 90 then
way = 50 'way 2 for 3K9
goto mainloop
endif
way = 51 'way 3 for 10K
mainloop:
SSPEN = 0 ' disable/enable SSP to reset port
SSPEN = 1
SSPBUF = "!" ' send reply $21 dec = 33
GoSub letclear ' wait for byte received
IF (SSPBUF <> "?") Then mainloop ' wait for ? to start conversion
toggle led
For i = 0 to 6 ' loop for 7 array locations
SSPBUF = dataout[i] ' send array variable
GoSub letclear ' wait until buffer ready
Next i ' next location
goto mainloop
letclear:
IF SSPIF = 0 Then letclear ' wait for interrupt flag
SSPIF = 0 ' reset flag
Return
End

Any idea ? Someone can help ?
Regards
herve
Bookmarks