Hello,
I seem to have trouble interfacing with a 25LC256 Microchop EEPROM unit.
I am using a 16LF88 which is capable of SSP but unable to write or read any data into it.
Proton was used to enter some code into the eeprom to verify the pin connection and whether the chip is functioning (by means of reading back after writing).
Data entered was by format:
Using GCB, I was unable to read or write any data into it.
Here is the code used to read:
Oh serial is working fine without problems, serial output is inverted (no MAX chip present)
Pin connections are located just after Variables:
Datasheet link if needed: http://ww1.microchip.com/downloads/en/devicedoc/21822e.pdf
;Chip Settings
#chip 16F88,4
#config BODEN=OFF, MCLR=OFF, OSC=INTRC_IO
;Defines (Constants)
#define SPIWREN 6 ;write enable 0000 0110
#define SPIWRITE 2 ;write 0000 0010
#define SPIRDSR 5 ;read register 0000 0101
#define SPIREAD 3 ;read 0000 0011
#define baud 833 ;1/baud 1/1200
#define halfbaud 416 ;place Read of SerRx in middle of bit
#define SerTxHigh Set PortB.5 Off
#define SerTxLow Set PortB.5 On
#define SerRx PortB.6
;Variables
Dim SPIADR(2)
Dim i As byte
Dim LCDValueTemp As byte
Dim SPIRCV As byte
Dim SPIXMIT As byte
Dir PORTA.0 OUT
Dir PORTB.3 OUT ;$CS$
DIR PORTB.1 IN ;SO
DIR PORTB.2 OUT ;SI
DIR PORTB.4 OUT ;SCK
DIR PORTB.6 IN ;Rx
DIR PORTB.5 OUT ;Tx
Set PORTB.3 Off
SPIMode MasterSlow
Set PORTB.3 On
For i = 0 to 2
SPIADR(i) = 0
Next
Ser_Init
'Main
start:
wait 2 s
EERD
SPIADRINC
XMIT_RS232 13
bin2ascii SPIRCV
goto start
'''increases addr by +1
Sub SPIADRINC
SPIADR(0) = SPIADR(0) + 1
If SPIADR(1) = 255 Then
SPIADR(1) = 0
SPIADR(0) = 0
End If
If SPIADR(0) = 255 Then
SPIADR(1) = SPIADR(1) + 1
SPIADR(0) = 0
End If
End Sub
'''Read; {read, addr, addr, data}
Sub EERD
Set PORTB.3 Off
SPITransfer SPIREAD,0
SPITransfer SPIADR(1),0
SPITransfer SPIADR(0),0
SPITransfer 0, SPIRCV
Set PORTB.3 On
End Sub
Sub Ser_Init
DIR PORTB.6 in ;Rx
DIR PORTB.5 out ;Tx
SerTxLow ;Initial RS232 idle state
End Sub
Sub RCV_RS232
RxWait:
IF SerRx Off then
goto RxWait ;wait for start bit
end if
wait halfbaud us ;do half bit time delay
If SerRx Off then
goto RxWait
end if
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud us
Rotate RxByte Right
If SerRx On then
Set RxByte.7 0
end if
If SerRx Off then
Set RxByte.7 1
end if
Next
wait baud us
End Sub
Sub XMIT_PRINT (PrintData As string)
PrintLen = PrintData(0)
if PrintLen = 0 then
exit sub
end if
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
End Sub
Sub XMIT_RS232 (In Xmit_Byte)
SerTxLow
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON then
SerTxHigh
end if
If Status.C Off then
SerTxLow
end if
wait baud us
Next
SerTxHigh
wait baud us
End Sub
Sub Bin2ascii (In LCDValue)
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
IF LCDValueTemp > 0 OR LCDValue >= 100 then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun)
End Sub
Guidance needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This should change GCBasic's default SPI signal to match what the 25LC256 expects.
The SPIADRINC sub doesn't look quite right either - I think it should test for the byte rolling round to zero rather than 255.
Alternatively you could use a word variable for the address rather than an array as arrays use indirect addressing in the assembly making the code significantly longer. You could do something like the following fragment -
Dim SPIADR as word alias SPIADR_msb, SPIADR_lsb
SPIADR = 0
Ser_Init
'Main
start:
wait 2 s
EERD
SPIADR ++ ' Increment address by 1
XMIT_RS232 13
bin2ascii SPIRCV
goto start
'''Read; {read, addr, addr, data}
Sub EERD
Set PORTB.3 Off
SPITransfer SPIREAD,0
SPITransfer SPIADR_msb,0
SPITransfer SPIADR_lsb,0
SPITransfer 0, SPIRCV
Set PORTB.3 On
End Sub
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I seem to have trouble interfacing with a 25LC256 Microchop EEPROM unit.
I am using a 16LF88 which is capable of SSP but unable to write or read any data into it.
Proton was used to enter some code into the eeprom to verify the pin connection and whether the chip is functioning (by means of reading back after writing).
Data entered was by format:
Using GCB, I was unable to read or write any data into it.
Here is the code used to read:
Oh serial is working fine without problems, serial output is inverted (no MAX chip present)
Pin connections are located just after Variables:
Datasheet link if needed: http://ww1.microchip.com/downloads/en/devicedoc/21822e.pdf
Guidance needed.
Hi,
Try adding a line after setting the SPIMode -
This should change GCBasic's default SPI signal to match what the 25LC256 expects.
The SPIADRINC sub doesn't look quite right either - I think it should test for the byte rolling round to zero rather than 255.
Alternatively you could use a word variable for the address rather than an array as arrays use indirect addressing in the assembly making the code significantly longer. You could do something like the following fragment -
Frank