I can get SPI working. No communications, a poor (very poor) clock signal and I cannot figure out.
So, issues:
1) I get an Error: 0 is not a variable and cannot be used for the parameter SPITRANSFER. When I used SPITransfer 0x0C, 0 (note the zero). If I use SPITransfer 0x0C, serBuf (note the variable) this compiles.
2) No comms to slave MAX7219. No communications and a clock signal that makes no sense to me on my scope.
~~~~~
#chip 16F1937, 4
#config Osc = intOSC
'Set SDI as an in and SDO as an out, CLK as output and the SS
Dir PORTC.3 OUT
Dir PORTC.4 IN
Dir PORTC.5 OUT
dir porta.0 out
Dim serBuf As byte
Dim seroutBuf As byte
' 1 = SS function is on RA0/AN0/C12IN0-/C2OUT/SRNQ/SS/SEG12/VCAP
SSSEL = 1
'Set SPI Mode to master
SPIMode Master
serBuf = 0x00
seroutBuf = 0x0c
do while (1)
SPITransfer 0x0C, serBuf
SPITransfer 0x01, serBuf
SPITransfer 0x09, serBuf
SPITransfer 0x0F, serBuf
SPITransfer 0x0A, serBuf
SPITransfer 0x0A, serBuf
SPITransfer 0x0B, serBuf
SPITransfer 0x03, serBuf
Loop
~~~~
Last edit: Anobium 2013-11-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you edit the HWSPI library and remove the Out in front of the SPIRxData parameter in the SPITransfer sub it will compile with 0. The downside is that GCBasic will then add extra code to clear SPIRxData or move a variable into SPIRxData before each call to SPITransfer. I wrestled with this myself as there are lots of occasions when the received data is meaningless and I wanted to put 0 in there to indicate that. In the end it seemed the least complicated approach was just to accept that a variable had to be used there and just use a dummy variable to retain the code savings by using Out on the SPIRxData.
There is an overloaded version of SPIMode that allows you to set 4 clock options that are defined at the top of the HWSPI library. One of them might sort out the clock problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Resolved: The documentation is incorrect. See either https://sourceforge.net/p/gcbasic/discussion/596084/thread/e5cc5f66/#112c or https://sourceforge.net/p/gcbasic/discussion/596084/thread/e5cc5f66/#bca2
Can someone help me resolve this issue?
I can get SPI working. No communications, a poor (very poor) clock signal and I cannot figure out.
So, issues:
1) I get an Error: 0 is not a variable and cannot be used for the parameter SPITRANSFER. When I used SPITransfer 0x0C, 0 (note the zero). If I use SPITransfer 0x0C, serBuf (note the variable) this compiles.
2) No comms to slave MAX7219. No communications and a clock signal that makes no sense to me on my scope.
~~~~~
#chip 16F1937, 4
#config Osc = intOSC
'Set SDI as an in and SDO as an out, CLK as output and the SS
Dir PORTC.3 OUT
Dir PORTC.4 IN
Dir PORTC.5 OUT
dir porta.0 out
Dim serBuf As byte
Dim seroutBuf As byte
' 1 = SS function is on RA0/AN0/C12IN0-/C2OUT/SRNQ/SS/SEG12/VCAP
SSSEL = 1
'Set SPI Mode to master
SPIMode Master
serBuf = 0x00
seroutBuf = 0x0c
do while (1)
SPITransfer 0x0C, serBuf
SPITransfer 0x01, serBuf
SPITransfer 0x09, serBuf
SPITransfer 0x0F, serBuf
SPITransfer 0x0A, serBuf
SPITransfer 0x0A, serBuf
SPITransfer 0x0B, serBuf
SPITransfer 0x03, serBuf
Loop
~~~~
Last edit: Anobium 2013-11-17
If you edit the HWSPI library and remove the Out in front of the SPIRxData parameter in the SPITransfer sub it will compile with 0. The downside is that GCBasic will then add extra code to clear SPIRxData or move a variable into SPIRxData before each call to SPITransfer. I wrestled with this myself as there are lots of occasions when the received data is meaningless and I wanted to put 0 in there to indicate that. In the end it seemed the least complicated approach was just to accept that a variable had to be used there and just use a dummy variable to retain the code savings by using Out on the SPIRxData.
There is an overloaded version of SPIMode that allows you to set 4 clock options that are defined at the top of the HWSPI library. One of them might sort out the clock problem.
Thanks for the insight. I have just been struggling with SPIMode and SPITransfer too.
Thank you. The workaround works. I have attached update documentation to assist others.
Last edit: Anobium 2013-11-17