PDA

View Full Version : Hardware SPI with MAX3111E



KHsu
- 7th August 2007, 13:13
Hi guys,

Is there a tutorial on hardware SPI? I am trying to establish hardware SPI between a PIC18F66J15 and MAX3111E UART and the problem I am having now is I can't seem to read the data from the UART. I have setup the SSP1CON and SSP1STAT registers on the microcontroller and the UART such that I can send data out to the UART and when the UART gets data I get appropriate interrupt on the microcontroller side. However, when I get an interrupt and go read in the data from the UART the value is always %11111111.

Any help would be appreciated. Here's a snippet of my code:


'****Port setup****
INTCON2.7 = 0 'Disable internal pull ups on port B
INTCON2.6 = 1 'RQ_RQ from FPGA is active high - rising edge interrupt
INTCON2.5 = 1 'FPGA_GPINT from FPGA is active high - rising edge interrupt
INTCON2.4 = 0 'Screw out is falling edge interrupt
INTCON2.3 = 0 'COMM interrupt is falling edge - active low interrupt.

'****Here is my SPI Setup****
SSP1STAT.7 = 0
SSP1STAT.6 = 1 'sample bit in the middle of data, data tx on rising edge
PIR1.3 = 0 'Clear the buffer status.
SSP1CON1 = %00100000 'enable SPI, Master mode, clk=FOSC/4 = 10MHz

'****Variable****
SPI_OUT_DAT var WORD SPI_IN_DAT var WORD[4]
SPICOM_PC_CS VAR PORTE.1

'****************Read UART***********
Read_UART:
'The host will always be sending a four byte comm string out so:
'First send all zeros to get UART to send out data
COM_PC_CS = 0
pauseus 5
SPI_OUT_DAT.lowbyte = 0
SPI_OUT_DAT.highbyte = 0
gosub Send_SPIData
pauseus 5
COM_PC_CS = 1
pauseus 10
SPI_IN_DAT = SSP1BUF
pauseus 5
return
'
'**********SPI SEND******************
Send_SPIData:
SSP1BUF = SPI_OUT_DAT.HIGHBYTE
while PIR1.3 = 0 wend
pauseus 1
PIR1.3 = 0 'Reset the flag
SSP1BUF = SPI_OUT_DAT.LOWByte
while PIR1.3 = 0
wend
pauseus 1
PIR1.3 = 0 'Reset the flag
return

Normnet
- 7th August 2007, 13:50
First try Shiftout and Shiftin then Hardware SPI.

Norm

Normnet
- 8th August 2007, 01:42
I haven't studied your code but here is an example:

The SPI mode allows 8-bits of data to be synchronously
transmitted and received, simultaneously.

Shiftin, Shiftout & their MSSP equivalent.


subREAD:
Low CS

''''Shiftout sSI,sCLK,msbfirst,[vOP_READ\8,sDONT_CARE\16,vADDRESS_READ\8,sDONT_CAR E\8]


SSPBUF = vOP_READ ' SEND DATA BYTE
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vDUMMY = SSPBUF

SSPBUF = 0 'DON'T CARE
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vDUMMY = SSPBUF

SSPBUF = 0 'DON'T CARE
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vDUMMY = SSPBUF

SSPBUF = vADDRESS_READ
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vDUMMY = SSPBUF

SSPBUF = 0 'DON'T CARE
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vDUMMY = SSPBUF


For z = 1 To 200

''''Shiftin sSO,sCLK,msbpre,[vREAD\8]

SSPBUF = 0
While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
vREAD = SSPBUF

Next

High CS

Return
As a PIC18F452 example see page 130 of 452 data sheet for your SPI configuration of
SSPSTAT = %01000000
SSPCON1 = %00100010

Norm