HI,
I have a project of two pics (18f4550 master and 18f4550 slave using spi )
the problem is when i start the simulation in Proteus I didn't find any problem , and everything is ok , But if I try to wire the circuit I got a corrupted data received in serial comm ?
could anyone please help me
the master code :
the slave code :
I'm using the following setting :
SMP = 0 ' Data input sampled at middle of data output time
CKE = 0 ' transmit of idle to active edge
CKP = 0 ' idle state is low level
SSPEN = 1 ' SSP Enable
and I am receiving the following in Serial com:
slave
000 255 255 255 255 255 255 255 255 255
slave
255 000 000 000 000 000 000 000 000 000
slave
000 255 255 255 255 255 255 255 255 255
slave
255 000 000 000 000 000 000 000 000 000
slave
000 255 255 255 255 255 255 255 255 255
slave
i have tried to use Pull up resistors for the SDO, SDI WITH 10K ohm but i
have received either 255 255 255 if i connect the resistor to the vdd
or 000 000 000 if resistor is connected to vss .
this is my Proteus simulation file in attachment
I have a project of two pics (18f4550 master and 18f4550 slave using spi )
the problem is when i start the simulation in Proteus I didn't find any problem , and everything is ok , But if I try to wire the circuit I got a corrupted data received in serial comm ?
could anyone please help me
the master code :
Rich (BB code):
Device 18F4550
Xtal = 48
Declare Stack_Size = 10
TRISB.0 = 1
TRISC.7 = 0
TRISB.1 = 0 'MASTER
'TRISB.1 = 1 'SLAVE
TRISA.5 = 1 'SLAVE
TXSTA.5=1 ' setting Transmit Enable Bit
RCSTA.7=1
RCSTA.4=1
Hserial_Baud 9600 ' Setting Baud rate
INTCON=0
INTCON2=0
INTCON3=0
PIE1=0
PIE2=0
Symbol WCOL = SSPCON1.7 'Write Collision Detect bit
Symbol SSPOV = SSPCON1.6 'Receive Overflow (SLAVE)
Symbol SSPEN = SSPCON1.5 'MSSP Enable/DISABLE bit
Symbol CKP = SSPCON1.4 'SCK Release Control bit
Symbol SSPM3 = SSPCON1.3 '0101:Slave ss disableed,0100:slave ss ena
Symbol SSPM2 = SSPCON1.2 '0011:master clock=tmr/2
Symbol SSPM1 = SSPCON1.1 '0010:master clock=fosc/64 ,0001: fosc/16
Symbol SSPM0 = SSPCON1.0 '0000:master clock=fosc/4
Symbol SMP = SSPSTAT.7 ' Sample bit (INSLAVE =0 )
Symbol CKE = SSPSTAT.6 ' SPI Clock Edge Select
Symbol BF = SSPSTAT.0 ' Buffer Full Status flag
Symbol GIE_GIEH INTCON.7 'GLOBAL Interrupts enable
Symbol PEIE_GIEL INTCON.6 'SIDE DEVICES INTERRUPT ENABLE
Symbol SSPIF PIR1.3 'Parallel rad/write finish FLAG
Symbol SSPIE PIE1.3 'PARALLEL INTERRUPTS ENABLE
Symbol SSPIP IPR1.3 'PARALEL PRIORITY
Symbol CS = PORTB.7 ' chip select pin
SSPCON1 = %00100010
Dim i As Byte ' loop index
Dim Byte_Out As Byte
Dim Byte_In As Byte
Dim DataOut[30] As Byte
Dim DataIn[30] As Byte
'//////////////////////////////////////////////////////////////////
DelayMS 500 ' Wait to stabilize
SMP = 0 ' Data input sampled at middle of data output time
CKE = 0 ' transmit of idle to active edge
CKP = 0 ' idle state is low level
SSPEN = 1 ' SSP Enable
High CS ' unselect slave
'//////////////////////////////////////////////////////////////////
Str DataOut = "give me the order hello",0 ' send to Slave
GIE_GIEH = 1
PEIE_GIEL = 1
SSPIE = 1
On_Interrupt GoTo Global_SPI
i=0
Dim t As Byte
Main:
HSerOut [Str DataOut,13]
For t = 0 To 3
SSPIE=0
Low CS ' enable Slave
For i = 0 To 26
'GoSub SPI_Function [DataOut], DataIn
SSPBUF =DataOut
While SSPIF = 0 : Wend 'BF WORK
SSPIF=0
DataIn= SSPBUF
Next
High CS
SSPIE=1 ' disable Slave
HSerOut ["master",13]
For i = 0 To 20
HSerOut [DataIn]
Next i
HSerOut [13]
'i=0
DelayMS 200
Next t
SSPIF=0 :i=0
'HSerOut [Bin1 SSPIF, " ",Bin1 BF," ",Bin1 WCOL," ",Bin1 SSPOV, 13]
GoTo Main
SPI_Function:
Pop SSPBUF ' pop directly to buffer
While SSPIF = 0 : Wend ' wait for end of transaction
SSPIF = 0 ' clear the SSP flag
Return SSPBUF ' push directly from buffer
Global_SPI:
Context Restore
Rich (BB code):
Device 18F4550
Xtal = 48
'SKAVE SETTING
Input PORTA
Input PORTB.0 'SDI INPUT
Output PORTC.7 'SDO OUTPUT
Input PORTB.1 'SCK INPUT
Input PORTA.5 'SS INPUT
Declare Stack_Size = 10
TXSTA.5=1 ' setting Transmit Enable Bit
RCSTA.7=1
RCSTA.4=1
Hserial_Baud 9600 ' Setting Baud rate
Symbol WCOL = SSPCON1.7 'Write Collision Detect bit
Symbol SSPOV = SSPCON1.6 'Receive Overflow (SLAVE)
Symbol SSPEN = SSPCON1.5 'MSSP Enable/DISABLE bit
Symbol CKP = SSPCON1.4 'SCK Release Control bit
Symbol SSPM3 = SSPCON1.3 '0101:Slave ss disableed,0100:slave ss ena
Symbol SSPM2 = SSPCON1.2 '0011:master clock=tmr/2
Symbol SSPM1 = SSPCON1.1 '0010:master clock=fosc/64 ,0001: fosc/16
Symbol SSPM0 = SSPCON1.0 '0000:master clock=fosc/4
Symbol SMP = SSPSTAT.7 ' Sample bit (INSLAVE =0 )
Symbol CKE = SSPSTAT.6 ' SPI Clock Edge Select
Symbol BF = SSPSTAT.0 ' Buffer Full Status flag
Symbol GIE_GIEH INTCON.7 'GLOBAL Interrupts enable
Symbol PEIE_GIEL INTCON.6 'SIDE DEVICES INTERRUPT ENABLE
Symbol SSPIF PIR1.3 'Parallel rad/write finish FLAG
Symbol SSPIE PIE1.3 'PARALLEL INTERRUPTS ENABLE
Symbol SSPIP IPR1.3 'PARALEL PRIORITY
Symbol CS = PORTA.5 ' chip select pin
SSPCON1= 0b00000100
Dim i As Byte '
Dim Byte_Out As Byte
Dim Byte_In As Byte
Dim DataOut[30] As Byte
Dim DataIn[30] As Byte
'//////////////////////////////////////////////////////////////
DelayMS 500
SMP = 0 ' Data input sampled at middle of data output time
CKE = 0 ' transmit of idle to active edge
CKP = 0 ' idle state is low level
SSPEN = 1 ' SSP Enable
Str DataOut = "AAAA BB CCC DDDD", 0 ' Slave
GIE_GIEH = 1
PEIE_GIEL = 1
SSPIE = 1
Dim t As Byte
On_Interrupt GoTo Global_SPI
Main:
GoTo Main
Global_SPI:
If SSPIF = 1 And BF = 1 Then
i=i+1
DataIn = SSPBUF
SSPBUF = DataOut
While SSPIF = 0 : Wend
SSPIF=0
If i = 26 Then
HSerOut ["slave",13]
For i = 1 To 26
HSerOut [DataIn]
Next i
HSerOut [13]
i=0
End If
End If
Context Restore
SMP = 0 ' Data input sampled at middle of data output time
CKE = 0 ' transmit of idle to active edge
CKP = 0 ' idle state is low level
SSPEN = 1 ' SSP Enable
and I am receiving the following in Serial com:
slave
000 255 255 255 255 255 255 255 255 255
slave
255 000 000 000 000 000 000 000 000 000
slave
000 255 255 255 255 255 255 255 255 255
slave
255 000 000 000 000 000 000 000 000 000
slave
000 255 255 255 255 255 255 255 255 255
slave
i have tried to use Pull up resistors for the SDO, SDI WITH 10K ohm but i
have received either 255 255 255 if i connect the resistor to the vdd
or 000 000 000 if resistor is connected to vss .
this is my Proteus simulation file in attachment
Attachments
-
66.2 KB Views: 24