Hardware SPI with MAX3111E
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