The MSSP always sends data MSB first.
<br>
Hello Darrel
my board work correct with this instruction
Shiftout sdata , sclk ,MSBFIRST, [var_out]
Do You know the correct SPI setup to use the hardware SPI to do that?
I try with this and have no function
'spi setup
SSPEN VAR SSPCON1.5 'SSP Enable bit
CKP VAR SSPCON1.4 'Clock Polarity Select
SMP VAR SSPSTAT.7 'Data input sample phase
CKE VAR SSPSTAT.6 'Clock Edge Select bit
TRISC = 0
CKP = 0 'clock idle low 'have changed to 1 for testing but no ok
CKE = 0 'transmit on idle to active transition 'have changed to 1 for testing
'but no ok
SSPIF = 0 'clear SPI interrupt
SMP = 0
main:
SSPEN = 1 'enable SPI pins
SSPBUF = var_out 'send array variable
Return
Have a idea how to fix that?
Thank You
Regards
Pedro
For MSBFIRST, you have it correct.
CKP = 0
CKE = 0
Which PIC are you using?
What OSC frequency are you using?
What is it sending data to?
Are you connected to the SDO/SCK pins of the pic?
SDO(PIC) to SDI(slave), AND SCK(PIC) to SCK(slave).
Also, in this code...Since no subroutine was called, the program will reset when it gets to the Return.Code:main: SSPEN = 1 'enable SPI pins SSPBUF = var_out 'send array variable Return
<br>
DT
Hi DarreL
Thanks for Your help
Here is a short code that work in the shiftout version, can you see why the
spi variant not work, i never used spi before.
The pic is 18F452 and the osc is 16Mhz
The data i sent to a little TFT display and with the Shiftout it works fine but a little slow
"Are you connected to the SDO/SCK pins of the pic?
SDO(PIC) to SDI(slave), AND SCK(PIC) to SCK(slave)."
Yes
Lcd_port var PORTC 'Using Port C in the program with the command
Rs var lcd_port.1
Cs var lcd_port.2
Sdata var Lcd_port.5 'spi out pin
Sclk var Lcd_port.3 'spi clk pin
DEFINE OSC 16
TRISC = 0
contrast var byte
lcd_out var byte
contrast = 1
'spi setup
SSPEN VAR SSPCON1.5 'SSP Enable bit
CKP VAR SSPCON1.4 'Clock Polarity Select
SMP VAR SSPSTAT.7 'Data input sample phase
CKE VAR SSPSTAT.6 'Clock Edge Select bit
SSPIF VAR PIR1.3 'interrupt flag - last bit set
CKP = 0 'clock idle low
CKE = 0 'transmit on idle to active transition
SSPIF = 0 'clear SPI interrupt
SMP = 0
main:
gosub adj_contrast
contrast = contrast + 1
pause 1000
goto main
adj_contrast:
Command = 0 'command
Lcd_out = $25 'comand contrast setting
Gosub Lcd_sendbyte
Command = 1 'Parameter
Lcd_out = contrast '..adjust contrast from 0...127
Gosub Lcd_sendbyte
return
Lcd_sendbyte:
SSPEN = 0 'desable SPI pins
cs = 0 'Cs = 0 to start of sequence
sclk = 0 'Clock line to 0
sdata = 1 '1 = parameter
If Command = 0 Then
sdata = 0 '0 = cmd
Endif
sclk = 1
'9 bit ' set it manual to indicate if the next byte is command or parameter
'----------------------------------------------------------------------
SSPEN = 1 'enable SPI pins
SSPBUF = lcd_out 'send variable
''''' Shiftout sdata , sclk ,MSBFIRST, [Lcd_out]' 'send bit after bit of the
'value of variable "Output"
cs = 1 'Cs to 1 at end of sequence
Return
Best regards
Pedro
Here's a possibility...
When you disable the SSP module, the pin goes to the state that it was last set to, independant of where the SSP left it.
After sending the ninth bit, it leaves sclk at 1. So the next time you disable the SSP the SCK pin will go back to 1 and clock in a "bad" bit. The rest of the bits will then be offset by one position.
Make sure to set the pin to the correct state before disabling the SSP.
DT
Hi.If i wanna send data from Master PIC to Slave PIC through SPI,can i follow the same concept that were provided in MELABS?.I had tried but it's not working.I am bit confused with clearing SSPBUF which i don't know whether i have to clear it in MASTER or in SLAVE?.Or,i am making mistake in timing?...
Bookmarks