View previous topic :: View next topic |
Author |
Message |
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Fri Feb 17, 2017 7:36 pm Post subject: Read Cypress Flash S25FL164K |
|
|
Hello
I have connected Cypress Flash S25FL164K with ATMEGA164p via SPI. I am not able to read the flash. has anyone worked with cypress flash before?
All I am doing is sending instruction ABh and as per datasheet I should get the device ID back. I have attached the datasheet for ref. Refer pg. 60, (6.6.1- Legacy Device Identification Commands)
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600 'this freq give 0.0% error for all baud rates up to 115200
$baud = 57600
$hwstack = 80 'used for GOSUB addresses {default is 32}
$swstack = 80 'default use 10 for the SW stack
$framesize = 80 'space size for Registers defining variables
Config Serialin = Buffered , Size = 8
Config Spi = Hard , Interrupt = Off , Data_order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
Spiinit
Dim Spi_buffer As Byte
Dim Read_data As Byte
Spi_buffer = &B10101011 ' send Instruction code ABh
Enable Interrupts
Reset Portb.4 ' Make CS/ low
Spiout Spi_buffer , 1
Spiin Read_data , 1
Waitms 1
Set Portb.4 ' Make CS/ high
Print Read_data
|
(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Fri Feb 17, 2017 10:56 pm Post subject: |
|
|
you must setup noss =0 and add a pin for CS sample code use portb.0 for CS
you must sent AB + 3 dumyi bytes
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600
$hwstack = 80
$swstack = 80
$framesize = 80
$baud = 57600
'SPI config
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 0
Spiinit
'CS pin setup a pin for CS
Chip Alias Portb.0
Config Portb.0 = Output
Set Chip
Dim Spi_buffer(6) As Byte
Dim Read_data(6) As Byte
Dim Inst As Byte
Declare Sub Read_id()
Enable Interrupts
Wait 1
Do
Call Read_id() '&HAB cmd
Wait 5
Loop
'(
When Used Only To Obtain The Device Id While Not In The Deep Power -down State,
shifting the instruction code ABh followed by 3-dummy bytes.
The Device Id Bits Are Then Shifted Out On The Falling Edge Of
Sck With Most Significant Bit(msb) First.
')
Sub Read_id()
Inst = &HAB ' send Instruction code ABh see 8.5.2
Spi_buffer(1) = Inst
Spi_buffer(2) = &H00 '3-dummy bytes
Spi_buffer(3) = &H00
Spi_buffer(4) = &H00
Reset Chip ' Make CS/ low
Spiout Spi_buffer(1) , 4 'sent ab + 3 dummy see 8.5.2
Spiin Read_data(1) , 1 'Read Device Id
Set Chip ' Make CS/ high
Print "ID : " ; Hex(read_data(1)) ; ' see 6.6.1
If Read_data(1) = &H14 Then Print " W25q16"
If Read_data(1) = &H16 Then Print " S25FL164K"
End Sub |
This is how i write read W25Q16dv
compare it to your datasheet
Code: | $regfile = "m328pdef.dat"
$crystal = 8000000
$baud = 38400
$hwstack = 64
$swstack = 64
$framesize = 80
'SPI config
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 0
Spiinit
'Chip Select handling of portB.0
'If the Noss = 1, the hardware SS internal management but are not limited,
'IMPORTANT!
'The Winbond W25Q16DV 16Mbit chip (also) organized WORD,
'So the CS rate is to be treated separately, as the HW-solving and bytes
' datasheet
'http://www.elinux.org/images/f/f5/Winbond-w25q32.pdf
'25q mcu
'/CS : Chip
'DO : MISO
'DI : MOSI
'Clk : Sck
'wp & hold pullup+3,3v
'CS pin
Chip Alias Portb.0
Config Portb.0 = Output
Set Chip
Declare Sub Jedec_id()
Declare Sub Device_id()
Declare Sub Parameter_page()
Declare Sub Read_data()
Declare Sub Write_data()
Declare Sub Clear_mem()
Declare Sub Clear_pp()
Declare Sub Write_dis()
Declare Sub Write_en()
Declare Sub Stbit()
Dim Sent_data(8) As Byte
Dim Sent_p(8) As Byte
Dim read_data_tmp(8) As Byte
Dim my_data(8) As Byte
Dim Data_in(4) As Byte ' the array of input data
Dim Data_out(8) As Byte ' the array of 'output data
Dim Mem_p As Byte
Dim St_bit As Bit
Dim Dummy As Byte
Dim Datas As Word
Dim Data_l As Byte At Datas Overlay
Dim Data_h As Byte At Datas + 1 Overlay
Dim Address As Long
Dim Addr_l As Byte At Address Overlay
Dim Addr_m As Byte At Address + 1 Overlay
Dim Addr_u As Byte At Address + 2 Overlay
Dim Addr_x As Byte At Address + 3 Overlay
Addr_x = 0
Enable Interrupts
Dim A As Word
Dim B As Byte
' W25Q16 (2097151 bytes) = 16 Mbit
Print "Start ."
Print "read chip id"
Call Jedec_id()
Print Hex(read_data_tmp(1)) ; Hex(read_data_tmp(2)) ; Hex(read_data_tmp(3))
Print
Print "read Manufacturer Device Id "
Call Device_id()
Print Hex(read_data_tmp(4)) ; Hex(read_data_tmp(5)) ; Hex(read_data_tmp(6))
Print
'call Clear_mem()
'(
')
'test for mem write data 256 bytes write
A = 0
Print "Write 255 bytes "
For Address = 0 To &HFF Step 2
Incr A
Data_h = Addr_m
Data_l = Addr_l
Call Write_data()
Print Hex(address) ; "h: " ; Hex(data_h) ; Hex(data_l)
Next
Print "Writeing DONE "
Wait 5
Print "data dump: "
wait 1
For Address = 0 To &HFF Step 2 '8191
Call Read_data()
Print Hex(address) ; "h: " ; Hex(my_data(1)) ; Hex(my_data(2))
Next
Print "Reading DONE "
End
' Manufacturing and Memory code reading
Sub Jedec_id()
Mem_p = &H9F
Reset Chip
Spiout Mem_p , 1
Spiin Read_data_tmp(1) , 3
Set Chip
'Call Stbit()
End Sub
Sub Device_id()
Mem_p = &H90
Reset Chip
Spiout Mem_p , 1
Spiin read_data_tmp(1) , 6
Set Chip
Call Stbit()
End Sub
' PARAMETER PAGE
Sub Parameter_page()
Address = 0 'Long type variable!
Sent_p(1) = &H53 'read parameter page
Sent_p(2) = &H00 'address 3 byte
Sent_p(3) = &H00 '000000
Sent_p(4) = &H00
Reset Chip
Spiout Sent_p(1) , 4
Spiin read_data_tmp(1) , 3
Set Chip
Addr_u = read_data_tmp(1)
Addr_m = read_data_tmp(2)
Addr_l = read_data_tmp(3)
Print "CHIP ID: " ; Read_data_tmp(1) ; Read_data_tmp(2) ; Read_data_tmp(3)
' address Checking
'Parameter page deleted?
If Address = &HFFFFFF Then '16777215
Address = 0
Print "Flash: empty "
Wait 2
Goto Zero
End If
'The memory is full? (Address = 1FFFFF)
If Address = &H1FFFFF Then '16777215
Print "Flash: full "
End If
Address = Address + 2
Zero:
Call Clear_pp()
Sent_data(1) = &H52 'parameter page write
Sent_data(2) = &H00 'dummy
Sent_data(3) = &H00 'dummy
Sent_data(4) = &H00 'address
Sent_data(5) = Addr_u 'data1
Sent_data(6) = Addr_m 'data2
Sent_data(7) = Addr_l 'data3
Sent_data(8) = &H00 'data4 -> empty because of a couple of bytes to be!
Call Write_en()
Reset Chip
Spiout Sent_data(1) , 8
Set Chip
Call Stbit()
Cls
End Sub
' RAM read
Sub Read_data()
my_data(1) = 0
my_data(2) = 0
Mem_p = &H03
Sent_data(1) = Mem_p
Sent_data(2) = Addr_u
Sent_data(3) = Addr_m
Sent_data(4) = Addr_l
Reset Chip
Spiout Sent_data(1) , 4
Spiin my_data(1) , 2
Set Chip
Call Stbit()
End Sub
' RAM write
Sub Write_data()
Mem_p = &H02
my_data(1) = Mem_p
my_data(2) = Addr_u
my_data(3) = Addr_m
my_data(4) = Addr_l
my_data(5) = Data_h
my_data(6) = Data_l
Call Write_en()
Reset Chip
Spiout My_data(1) , 6
Set Chip
Call Write_dis()
Call Stbit()
End Sub
' Clear RAM
Sub Clear_mem() ' clear flash ram
Call Write_en()
Mem_p = &HC7
Reset Chip
Spiout Mem_p , 1
Set Chip
Call Stbit()
End Sub
' Clear PARAMETER PAGE
Sub Clear_pp() ' clear parameter page
Call Write_en()
Mem_p = &HD5
Reset Chip
Spiout Mem_p , 1
Set Chip
Call Stbit()
End Sub
' WRITE Disable - Enable
Sub Write_dis() ' write disable
Mem_p = &H04
Reset Chip
Spiout Mem_p , 1
Set Chip
End Sub
Sub Write_en() ' write enable
Mem_p = &H06
Reset Chip
Spiout Mem_p , 1
Set Chip
End Sub
' STATUS bit
' It will only be over when the memory of the transactions are finished!
Sub Stbit()
St_bit = 0
Kezd:
Mem_p = &H05
Reset Chip
Spiout Mem_p , 1
Spiin Dummy , 1
Set Chip
St_bit = Dummy.0
If St_bit = 0 Then Exit Sub
Goto Kezd
St_bit = 0
End Sub |
data via comport :
Quote: | [00]Start .
read chip id
EF4015
read Manufacturer Device Id
14EF14
Write 255 bytes
00000000h: 0000
......
000000FEh: 00FE
Writeing DONE
data dump:
00000000h: 0000
.........
000000FAh: 00FA
000000FCh: 00FC
000000FEh: 00FE
|
_________________ / Kim |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Mon Feb 20, 2017 8:52 pm Post subject: |
|
|
Thanks Kim for your response.
Code: | 'SPI config
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 0
Spiinit
' I am using SS/ pin of Atmega164p i.e. PORTB.4 as CS/ for Flash. i.e. Noss =0 ; ( The NOSS parameter with a value of 1, will not set the SS line to logic 0 when the SPI operation begins.) |
I tried sending 3dummy bytes after ABh instruction although the datasheet of the flash I am using(S25FL164K) does not say that is reqd.
The MISO line is high all the time and the SPIIN reads FF. If I send on ABh and no dummy bytes, it is still high all the time.
Hardware connections:
ATMEGA164P (44pin)
MOSI (PORTB.5) to MOSI of flash
MISO (PORTB.6) to MISO of Flash
SCK ( PORTB.7) to SCLk of Flash
SS/(PORTB.4) to CS/ of Flash
Is there anything else I should look in to |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Tue Feb 21, 2017 8:37 am Post subject: |
|
|
did you config PORTB.4 as output ?
and Set Portb.4 after config to output
Quote: | I tried sending 3dummy bytes after ABh instruction although the datasheet of the flash I am using(S25FL164K) does not say that is reqd. |
datasheet say it loud & clear page 78 see 8.5.2
Quote: | When Used Only To Obtain The Device Id While Not In The Deep Power -down State,
shifting the instruction code ABh followed by 3-dummy bytes.
The Device Id Bits Are Then Shifted Out On The Falling Edge Of
Sck With Most Significant Bit(msb) First. |
_________________ / Kim |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Tue Feb 21, 2017 4:19 pm Post subject: |
|
|
Thanks Kim
I am able to read the device ID now.
I made Noss=1 in Config SPI, and Used Set and Reset for PORTB.4 |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 22, 2017 2:37 am Post subject: |
|
|
Good
pls post the working code you have
for other users with same issues _________________ / Kim |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|