Microchip SRAM
iemand
Posts: 5
Hello all,
I am trying to get a microchip sram 23k256 ic working. I used the winbond flash and microchip sram driver from the object excange.
This is my code: (whitch doesnt work, I only read a 9, 0 or 255 instead of the value it should be)
I think that I am doing something wrong with the variables (@ or not @?).
I am trying to get a microchip sram 23k256 ic working. I used the winbond flash and microchip sram driver from the object excange.
This is my code: (whitch doesnt work, I only read a 9, 0 or 255 instead of the value it should be)
CON _clkmode = xtal1 + pll8x _xinfreq = 10_000_000 'Audio / video output L_Audio = 5 'Sound (L) output R_Audio = 6 'Sound (R) output COMPOSITE_VIDEO = 12 'Video output 'Controllers PS2_toetsenbord_dat = 16 'Toetsenbord data i/o PS2_toetsenbord_clk = 17 'Toetsenbord clk output PS2_muis_dat = 3 'Muis data i/o PS2_muis_clk = 4 'Muis clk output gc_controller_1 = 7 'Gamecube controller 1 data i/o gc_controller_2 = 8 'Gamecube controller 2 data i/o 'Intern RAM geheugen SRAM_CLK = 1 'RAM clk output SRAM_DIO_DI = 2 'RAM data output SRAM_DO = 9 'RAM data input SRAM_CS1 = 10 'RAM chipselect 1 SRAM_CS2 = -1'11 'RAM chipselect 2 (niet gebruikt, zie EXP_P8) 'SD kaart aansluiting SD_CARD = 24 'SD Kaart basepin spiDO = 24 'SD Kaart data input spiClk = 25 'SD Kaart clk output spiDI = 26 'SD Kaart data output spiCS = 27 'SD Kaart chip select 'Interne eeprom chip voor bootloader eeprom_clk = 28 'EEPROM clk output eeprom_dat = 29 'EEPROM data i/o 'Interne communicatie met PIC chip serial_tx = 30 'PIC tx output serial_rx = 31 'PIC rx input 'Uitbreidingspoort (universeel) EXP_P0 = 18 EXP_P1 = 19 EXP_P2 = 20 EXP_P3 = 21 EXP_P4 = 22 EXP_P5 = 23 EXP_P6 = 5 EXP_P7 = 0 'Nu nog een LED! EXP_P8 = 11'Was voor SRAM CS! VAR byte sram_data, sram_adres, sram_data_check OBJ text : "TV_Text_Half_Height" ram : "ram_flash" PUB start | i text.start(12,1,0,40,15) repeat enter text.ink(5&7) text.str(string("RAM TEST")) enter text.ink(6&7) text.str(string("v1.4")) 'text.inkblock(5,2,30,11,1) ram.start(-1, SRAM_CLK, SRAM_DIO_DI, SRAM_DO, SRAM_CS1, SRAM_CS2) text.ink(2&7) 'TEST RAM enter text.str(string("Writing SRAM... (adr 0 t/m 20)")) enter sram_data:= 0 sram_adres:= 0 repeat 20 text.str(string(".")) ram.writeSRAM(@sram_adres, @sram_data, -1) sram_data:= sram_data + 2 sram_adres:= sram_adres + 1 waitcnt(cnt+1_000_000) enter text.str(string("Reading SRAM... (adr 0 t/m 20)")) enter sram_data:= 9 sram_data_check:= 0 sram_adres:= 0 repeat 20 'if sram_adres == 100 ' quit ram.readSRAM(@sram_adres, @sram_data, -1) sram_data_check:= sram_data_check + 2 sram_adres:= sram_adres + 1 if not (sram_data == sram_data_check) enter text.str(string("Error occured on adress ")) text.dec(sram_adres) text.str(string(".")) enter text.str(string("Read: ")) text.dec(sram_data) text.str(string(", should be: ")) text.dec(sram_data_check) text.str(string(".")) waitcnt(cnt+40_000_000) else text.str(string("Actie succesvol!")) enter waitcnt(cnt+40_000_000) waitcnt(cnt+160_000_000) PUB cls text.out($00) text.out($01) PUB enter text.str(string($0D))
I think that I am doing something wrong with the variables (@ or not @?).
Comments
ram.writeSRAM(@sram_adres,·@sram_data,·-1)
the first parameter is the address in the SRAM and not the address of the sram_adres variable. You really want to give this function the 0 for addressing byte 0 in the SRAM. Whenever you really want to pass the value of a variable, there is no @ involved.
@sram_data seems to be ok.
-1 ? Is that the number of bytes you want to write to the SRAM? Gonna have a look into your archieve to be a better help ....
So, you have to say:
sram_data := ram.readSRAM( sram_adres, 0 , -1)
or
ram.readSRAM( sram_adres, @sram_data, 1 )
The write works similar
ram.writeSRAM( sram_adres, sram_data, -1)
or
ram.writeSRAM( sram_adres, @sram_data, 1 )
The functions have been designed like that to support direct value passing or passing bigger amount of data by buffers.