PDA

View Full Version : 18f242 Mssp



Ron Marcus
- 12th November 2005, 16:06
I am working with the 18F242 MSSP configured for a master SPI. It is not working for me, and wondered if anyone could shed some light. I have read the (fine) manual until my fingers are dog eared. Double checked all settings for the registers, but near as I can tell, there are still no comms. To double check that the protocol worked, I used shiftin/shiftout with the same pins, and everything works fine.
When I flip the control bit for SPI enable, I get a clock, I believe I am getting data out, but for input, I get the dummy data I put in SSPBUF to initiate a transfer. What am I missing?

Ron Marcus
- 12th November 2005, 16:52
I forgot the register set up. Sorry...

; MSSP REGISTER SETUP
BF VAR SSPSTAT.0 ; Buffer full status
CKE var SSPSTAT.6
SMP var SSPSTAT.7
WCOL VAR SSPCON1.7 ;Transmit write collision detect bit
SSPEN VAR SSPCON1.5 ; Enable MSSP
CKP var SSPCON1.4
SDI var PORTC.4 ; Synchronous data input
SDO var PORTC.5 ;Synch data output
SCK VAR PORTC.3 ;Synch clock output


SSPSTAT = %10000000
SSPCON1 = %00010010 ; SS port enable,idle high,SPI master clock/16
'************************************************* ****************
Main:
UART_SPI = 0
TRISC.2 = 0 :TRISC.3 = 0 :TRISC.4 = 1:TRISC.5 = 0 :TRISA.5 = 1
SMP = 0 : CKE = 0 : CKP = 1
Alfat_power = 1
pause 1500

I enable the SPI a little later in the program

arniepj
- 12th November 2005, 18:58
I believe the key to making it work was the pir1.3 interrupt.I used the MSSI port a while back with a Max1270 A/D chip.Attached is that code,look under Data Aquisition.

Ron Marcus
- 12th November 2005, 19:47
I believe the key to making it work was the pir1.3 interrupt.I used the MSSI port a while back with a Max1270 A/D chip.Attached is that code,look under Data Aquisition.

I will try this, but...
I am not using an interrupt in this application. Does it still need to be reset after every transmission?

Ron

Ron Marcus
- 13th November 2005, 03:29
O.K. I got it up and runnung. The interrupt flag idea led me to check all the flag bits. It turned out the buffer full flag was put in the wrong place and the program was running past the buffer before it was full. Thanks for the lead.

Ron