Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

EEPROM 93C HELP
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Wed Feb 01, 2017 8:16 am    Post subject: EEPROM 93C HELP Reply with quote

hello hello , this time i'm in deep trouble i think.
Just started to work with EEPROM interface, i have 93C46, and as i understood to use "$EEPOM", "EEPROMWRITE" and etc, i need a $lib, which doesnt exist with 93C46.
I serached a forum and found this link from "grifo"
http://www.grifo.com/CORSO/uk_BASCOM_AVR/uk_Capitoli_AVR/uk_BASAVR_047.BAS
It coded for "93LC46A", i checked Datasheet of mine, and datasheet of 93LC46A, thos EEPROM's have the same WRITE and READ timing.
Therefore i started to explore this code. But due to the fact that im only around 3 week programming in BASCOM, some thngs looks inconceivable for me.
I will not copy past a full example here, because you can just check URL above. I have 16 bit memory model

Code:
 Do                                                        ' Begin endless loop
    Print                                                   ' Shows menu with available operations
    Print "R -> Read location"
    Print "W -> Writee location"
    Print "E -> Enable erase and write"
    Print "D -> Disable erase and write"
    Print "Perform the choice by pushing the associated key: ";
    Choice = Waitkey()                                      ' Wait selection of operation to execute
    Printbin Choice                                         ' Shows performed choice
    Print
    If Choice >= "a" Then                                   ' If choice is lower case
      Choice = Choice And &HDF                              ' Convert it in upper case
    End If
    Print                                                   ' Separate menu from following visualizations
    Select Case Choice                                      ' Check converted choice
      Case "R":                                             ' Selected operation is read EE location
        Input "Addrress of location to read (0..128): " , Addmw
        Call Read_mwee()                                    ' Read byte from Microwire EE
        Print "Read data= " ; Datmw
        Call Ask_key()                                      ' Ask and wait a key pressure on console to allow results reading
      Case "W":                                             ' Selected operation is write EE location
        Input "Addrress of location to write (0..128): " , Addmw
        Input "Data to write (0..255): " , Datmw
        Call Write_mwee()                                   ' Write byte on Microwire EE
        Print "Write performed."
        Call Ask_key()                                      ' Ask and wait a key pressure on console to allow results reading
      Case "E":                                             ' Selected operation is enable erase and write operations
        Call Enaew_mwee()                                   ' Enable erase and write operations on Microwire EE
        Print "Erase and write operations enabled."
        Call Ask_key()                                      ' Ask and wait a key pressure on console to allow results reading
      Case "D":                                             ' Selected operation is disable erase and write operations
        Call Disew_mwee()                                   ' Enable erase and write operations on Microwire EE
        Print "Erase and write operations disabled."
        Call Ask_key()                                      ' Ask and wait a key pressure on console to allow results reading
      Case Else:                                            ' Selected operation is not valid
        Printbin &H07                                       ' Generate an advise BEL on console
    End Select
  Loop                                                      ' End endless loop
End



After we declarated subroutines and variables, here we have a main code, I send "R", from my PC console , and get to the case "choice" where i should send from PC "Addrress of location to read (0..128): " I tried to send 1 in ASCII in byte and hex, no respons, it just duplicate my sendings. Here we got the first incomprehension.
-----
Then i dont get what is
Code:
 Printbin &H07
do? We send received info in HEX data?
----
Code:
Sub Read_mwee()
  Pincs = 1                                                 ' CS signal at high level
  Call Com_mw(&H06 , Mwin , 3)                              ' Send 3 bits of READ command to Microwire EE
  Call Com_mw(addmw , Mwin , 7)                             ' Send 7 bits of address to Microwire EE
  Call Com_mw(&H00 , Mwin , 8)                              ' Get 8 bits of data to read from Microwire EE
  Datmw = Low(mwin)
  Pincs = 0                                                 ' CS signal at low level
End Sub
 


Code:
Call Com_mw(&H06 , Mwin , 3)
here we send 3 bits becouse we need " 1 1 0" on our "DI" port the makes our EEPROM "wakes up" and recieve adress.
But why then we send 7 bits of our address instead of 6?
Code:
Call Com_mw(addmw , Mwin , 7)  

Also, why we get 8 instead of 16? And also what "&H06", "&H00" do?
As you see have a lot of questions about this, thank you in further for your help. I will post a working code for sure later, because not only i who was looking for this.

(BASCOM-AVR version : 2.0.7.8 )


Last edited by jeezywonder on Thu Feb 02, 2017 4:18 am; edited 2 times in total
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Thu Feb 02, 2017 3:13 am    Post subject: Reply with quote

due to inactivity of the forum, i tried to write my simplest code to read a byte from "000 000" memery cell, just to understand how EEPROM works,
pretty confident that its wrong, but i tried as i can, any help appreciate it, commented coments mean what im trying to do. I attached "the READ mode figure" to the post, I would very much appreciate if someone could spend some of his time explaining this to me thanks in advance.
Quote:

The communication is performed through 4 different signals:
1) The first (/CS) enables the EEPROM.
2) Tthe second (CLK) supplies Timings and Synchronizations.
3) The third (DI) sends data to device.
4) The fourth signal (DO) acquires data from the device.

Code:
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 8
$framesize = 24
$baud = 9600
Config Portc.0 = Output
Config Portc.1 = output
Config Portc.2 = output
Config Portc.3 = input
Clk Alias Portc.1            ' Output
Cs Alias Portc.0              ' Output
Di Alias Portc.2                ' Output
Do1 Alias Portc.3             ' Input
Dim A As Byte
Dim B As Byte
Do
B = Inkey()                           ' waiting for command from console
If B <> 0 Then
Clk = 0
Waitms 10
Cs = 0
Waitms 10
Di = 0
Cs = 1                 ' Enables EEPROM
Waitms 10
Di = 1                  ' start bit, when Di = 1 and Cs = 1, and when di = 0(below)  from here our microwire knows that we want to read data.
Waitms 10
Cs = 1
Waitms 10
Clk = 1
Waitms 10                                                
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Di = 0              'here
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
'===========Adress==========

Clk = 1                              '  read a address from "0" memory cell
Waitms 10
Clk = 0                               '  6 bits to make EEPOM realize the adress
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
'==========================
Waitms 10     ' here we output the data through DO
Clk = 1         '   16 bits
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10
Clk = 0
Waitms 10
Clk = 1
Waitms 10
Clk = 0
Waitms 10


 Print Do1                                         ' Print data from "0" memort cell
 End If
   Loop


Last edited by jeezywonder on Thu Feb 02, 2017 6:46 am; edited 1 time in total
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Thu Feb 02, 2017 6:16 am    Post subject: Reply with quote

I checked my Chip Serial, Serial Clock, Data in and Data out with Oscilloscope.
I receive data from PC and send data to pc, but i always get 0 value. Seems like my "d01" didnt memirize the values and just ouput the last one which equals 0
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Thu Feb 02, 2017 7:55 am    Post subject: Reply with quote

I'm confused with how we read a data from memory cell, for example:
I have port "DO"( data out) on my EEPROM, then config our EPROM "data out" port for input:
Code:
Config Portc.3 = input

Then make a variable

Code:
Do1 Alias Portc.3             ' Input

Then due to the fact that ports can't store any data, i make an another varibale witch equals "DO" :
Code:
Dim z as Byte
Z = Do1

Therefore Z storing a 1 byte now.
But how this "Z" variable reads the data from EEPROM address? Becouse after our DI and CLK equal 1
EEPROM gets ready and it waitinig for address, which we indicate with DI = 0, then we toggle a Clock Serial to make EERPOM read the full 8 bit adress, it how i understand it
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1918
Location: Denmark

denmark.gif
PostPosted: Thu Feb 02, 2017 12:52 pm    Post subject: Reply with quote

Hi

Wy dont you just use shiftout / shiftin
93c46 is 1K: 128 x 8 or 64 x 16

for 8bit read/write :
so for read shiftout 9 bits Instruction (read 3 bits 110) (address 6 bits) read + address ,9
and shiftin 8 bits

reset cs pin 50ms before you start
msb first

CS = 1
shiftout xxxxxxxxxxxxxxx
Shiftin xxxxxxxxxxxxxxxx
cs = 0


read help about shiftout/in

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Bufalo

Bascom Member



Joined: 27 Jan 2017
Posts: 12

PostPosted: Thu Feb 02, 2017 2:39 pm    Post subject: Reply with quote

Tried to use EEPROM too, but didnt get it too
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Thu Feb 02, 2017 2:41 pm    Post subject: Reply with quote

Kimmi much thanks, its more clear now
But Honestly, its hard to visualize and without practice its harder, i have 64 x 16
And i still dont get where and how do we put our adress, for get access to ZERO memory cell, sorry for that

I tried to wrote some sample:
Code:
Config Portc.0 = Output
Config Portc.1 = output
Config Portc.2 = output
Config Portc.3 = input
dim clock as byte, sinp as byte, cs as byte
dim Intr as Integer                                        ' cuz have we 16 bit type of EEPROM
clock Alias Portc.1
Output Alias Portc.2                                      
sinp Alias Pinc.3
 '*******Main************
Waitms 50
Cs = 1
Shiftout Output , Clock , Intr , 1 , 9   ' puted one because MSB first,clock high due to datasheet as i understand
Shiftin Sinp , Clock , Intr , 1 , 9
Cs = 0
Print sinp
End
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1918
Location: Denmark

denmark.gif
PostPosted: Thu Feb 02, 2017 3:52 pm    Post subject: Reply with quote

Hi,
here is a test setup
!!!did not test it on real hardware !!!
but maby you can use some of it and read the datasheet !
Code:

'(
'$sim
http://www.atmel.com/Images/doc5140.pdf
AT93C46  1K: 128 x 8 or 64 x 16
')
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 32
$swstack = 32
$framesize = 32
'$baud = 9600

Cs Alias Portd.2
Config Portd.2 = Output

Pin_out Alias Portd.3
Config Portd.3 = Output

Pin_in Alias Pind.4
Config Pind.3 = Input

Sck Alias Portd.5
Config Portd.5 = Output


Declare Sub Read_data_93c46(byval A As Byte , Byval B As Byte)
Declare Sub Write_data_93c46(byval A As Byte , Byval B As Byte)
Declare Sub Setup_93c46()

Dim R_data(128) As Byte                                     '  1K: 128 x 8bit
Dim W_data(128) As Byte                                     '  1K: 128 x 8bit
Dim Count As Byte , A As Byte , B As Byte

Dim My_93c46 As Word
Dim Adr_93c46 As Byte At My_93c46 Overlay
Dim R_w As Byte At My_93c46 + 1 Overlay

Dim R_93c46 As Byte
R_93c46 = &B00000110

Dim W_93c46 As Byte
W_93c46 = &B00000101

Dim Read_enable As Byte
Read_enable = &B00010011


Cs = 0
Call Setup_93c46()                                          ' Enable serial EEPROM    (EWEN):
Waitms 50
Do
For Count = 1 To 128                                        '  1K: 128 x 8
   W_data(count) = Count
'sent
   Call Write_data_93c46(w_93c46 , Count)
   Waitms 10
'read
Call Read_data_93c46(r_93c46 , Count)
Waitms 10
Next
Wait 5
Loop
End



Sub Read_data_93c46(byval A As Byte , Byval B As Byte)
  R_w = A
  Adr_93c46 = B
'read from eeprom             3+6       '&B110+address   9 bits
   CS = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40
   Shiftin Pin_in , Sck , R_data(adr_93c46) , 1 , 8 , 40
   Cs = 0
   Waitms 10
End Sub



Sub Write_data_93c46(byval A As Byte , Byval B As Byte )
   R_w = A
  Adr_93c46 = B
' write address and data
   Cs = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40           ' Send address and data
   Cs = 0
   Waitms 10
End Sub

Sub Setup_93c46()
' Enable serial EEPROM
   Cs = 1
   Shiftout Pin_out , Sck , Read_enable , 1 , 5 , 40        ' Send write enable command
   Cs = 0
   Waitms 10
End Sub
 

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Fri Feb 03, 2017 3:52 am    Post subject: Reply with quote

I tried it, but to check it i have to know which variable i should to PRINT out?
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Fri Feb 03, 2017 10:47 am    Post subject: Reply with quote

Ok, after i killed a whole day to finally understand, that shifting procedure, much thanks to you kimmi, and your posted code, i did step by step.
If you can see on a code below, somehow a had to put "2 LSB shifted in first when clock goes low" option instead of 1. After that i get my vale on the console.
it was 8080(HEX).
Code:
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 8
$framesize = 24
$baud = 9600

Cs Alias Portc.0
Config Portc.0 = Output
Pin_out Alias Pinc.3
Config Portc.3 = Input                                      
Pin_in Alias Portc.2
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output
'*********************************
Dim My_93c46 As Word
Dim Send_adress As Word
'Send_adress = &B000000011
Dim Read_enable As Word
Read_enable = &B0000011
Declare Sub Setup()
Dim Count As Byte
'******** Main Programm ***********
Cs = 0                                                      '
Call Setup()
Do
Waitms 50
For Count = 1 To 64
Cs = 1
Shiftout Pin_in , Sck , Read_enable , 2 , 9            ' Here 2 istead of 1, wonder why due to data shit it should be 1
Shiftin Pin_out , Sck , Send_adress , 1 , 16
Cs = 0
Waitms 150
Print Send_adress
Next
Loop
End

'*************Sub*****************
Sub Setup()                                                 '
Cs = 1
Shiftout Pin_out , Sck , Read_enable , 1 , 1 , 40           ' Read_enable = &B0000011  
Cs = 0
Waitms 10
End Sub
 

Much tanks to kimmi again,
next step is to write a "for - next" loop, which should read datas from all memory cell, as i have 64x16 chip, that i need to read 64.
I tried by my own forces, but it doesnt work, seems to "subs+for loops + OVERLAY as" can help, due to your example, kimmi.
Here is the code. Whats im missing? Any tips? PS: Again i will share my code after i done
Code:
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 8
$framesize = 24
$baud = 9600

Cs Alias Portc.0
Config Portc.0 = Output
Pin_out Alias Pinc.3
Config Portc.3 = Input                                    
Pin_in Alias Portc.2
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output
'*********************************
Dim My_93c46 As Word
Dim Send_adress As Word
'Send_adress = &B000000011
Dim Read_enable As Word
Read_enable = &B0000011
Declare Sub Setup()
Declare Sub Read_data_93c46(byval A As Byte , Byval B As Byte)
Dim Count As Byte
Dim R_data(64) As Byte
Dim Adr_93c46 As Byte At Send_adress Overlay                ' Overlay( Anr_93c46 into My_9c46)
Dim R_w As Byte At Send_adress + 1 Overlay
 Dim R_93c46 As Byte
R_93c46 = &B00000110
'******** Main Programm ***********
Cs = 0                                                      '
Call Setup()
Do
Waitms 50
For Count = 1 To 64
Call Read_data_93c46(r_93c46 , Count )
Next
Loop
End

'*************Sub*****************

Sub Read_data_93c46(byval A As Byte Byval B As Byte)
R_w = A                                                     ' R_w(As Byte At My_93c46 + 1 Overlay) = A(
Adr_93c46 = B
Shiftout Pin_in , Sck , Read_enable , 2 , 9
Shiftin Pin_out , Sck , Send_adress , 1 , 16
Cs = 0
Waitms 150
End Sub
Sub Setup()                                                 '
Cs = 1
Shiftout Pin_out , Sck , Read_enable , 1 , 1 , 40           ' Read_enable = &B00000011
Cs = 0
Waitms 10
End Sub
 
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1918
Location: Denmark

denmark.gif
PostPosted: Fri Feb 03, 2017 12:39 pm    Post subject: Reply with quote

here is a test for 64x16

And i made wrong setup in overlay
be cause of the 3+6 for w/r + address and forgot to add data sent


here is a test new with VAR long and shift data to long

Code:
'(
http://www.atmel.com/Images/doc5140.pdf
AT93C46  1K: 128 x 8 or 64 x 16

'***********************************************************
' 64 x 16 bit sent      r/w  addr    data 16 bit
W addr + data : 0000000 101 000000 xxxxxxxxxxxxxxxx
' 64 x 16 bit read                     r/w  addr    data 16 bit
R addr + data: 00000000000000000000000 110 000000 xxxxxxxxxxxxxxxx

read data will be 4000 + count_x  
4000 to 4063

')
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32
$baud = 9600

Cs Alias Portc.0
Config Portc.0 = Output
Pin_out Alias Pinc.3
Config Portc.3 = Input
Pin_in Alias Portc.2
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output

Declare Sub Read_data_93c46()
Declare Sub Write_data_93c46()
Declare Sub Setup_93c46()

Dim R_data(64) As Word                                      '  1K: 64x16bit
Dim Count As Byte , Count_x As Byte
Dim My_data As Word
Dim My_93c46 As Long
Dim R_93c46 As Byte
R_93c46 = &B00000110
Dim W_93c46 As Byte
W_93c46 = &B00000101
Dim Read_enable As Byte
Read_enable = &B100110000                                   '64x16
Cs = 0

' Enable serial EEPROM    (EWEN):
Call Setup_93c46()

Waitms 50

Do
   For Count = 1 To 64                              '  1K: 64*16
     Count_x = Count - 1
     'setup sent data
      My_93c46 = W_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
      Shift My_93c46 , Left , 16
      My_data = 4000 + Count_x
      My_93c46 = My_93c46 + My_data                         ' as word

'sent
      Call Write_data_93c46()
      Waitms 4
      Print "W addr + data : " ; Bin(my_93c46)              '  1K: 64*16
      'W addr + data : 101 000001 (xxxxxxxxxxxxxxxx) is data sent

      'setup read data
      My_93c46 = R_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
'read
      Call Read_data_93c46()
      Print "R addr + data: " ; Bin(my_93c46) ; Bin(r_data(count))
     ' R addr + data: 011 0000001 (xxxxxxxxxxxxxxxx) is data read
      Waitms 4
   Next
   Wait 5
Loop
End



Sub Read_data_93c46()
'read from eeprom    3+6       '&B110+address   9 bits
   CS = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40
' read data 2 bytes
   Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40
   Cs = 0
   Waitms 10
End Sub



Sub Write_data_93c46()
' write address and data 2 bytes
   Cs = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40          ' Send address and data
   Cs = 0
   Waitms 10
End Sub

Sub Setup_93c46()
' Enable serial EEPROM   1 byte
   Cs = 1
   Shiftout Pin_out , Sck , Read_enable , 1 , 9 , 40         ' Send write enable command
   Cs = 0
   Waitms 10
End Sub

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1544

blank.gif
PostPosted: Fri Feb 03, 2017 8:42 pm    Post subject: Reply with quote

Quote:
Code:
Dim Read_enable As Byte
Read_enable = &B100110000

9 bit-bytes?

As My_93c46 is a 32 bit signed integer, the code as shown shifts out My_93c46's bit 31 to 24:
Quote:
Code:
Dim My_93c46 As Long
'...
Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40

I can't notice anywhere in the code how useful payload, opcode & address, gets into these positions after all.
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1918
Location: Denmark

denmark.gif
PostPosted: Fri Feb 03, 2017 9:30 pm    Post subject: Reply with quote

Tnx MWS

MSB first right ! so shift all to left


Code:
Dim Read_enable As Word
Read_enable = &B1001100000000000
Shiftout Pin_out , Sck , Read_enable , 1 , 9 , 40


Code:
Do
   For Count = 1 To 64                                      '128 Step 2                              '  1K: 64*16
     Count_x = Count - 1

     'setup sent data
      My_93c46 = W_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
      Shift My_93c46 , Left , 16
      My_data = 4000 + Count_x
      My_93c46 = My_93c46 + My_data                         ' as word
      Shift My_93c46 , Left , 7
      ' Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40

'sent
      Call Write_data_93c46()
      Waitms 4
      Print "W addr + data : " ; Bin(my_93c46)              '  1K: 64*16
      'W addr + data : 101 000001 (xxxxxxxxxxxxxxxx) is data sent

      'setup read data
      My_93c46 = R_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
      Shift My_93c46 , Left , 23
      '   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40
      ' Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40
'read
      Call Read_data_93c46()
      Print "R addr + data: " ; Bin(my_93c46) ; Bin(r_data(count))
     ' R addr + data: 011 0000001 (xxxxxxxxxxxxxxxx) is data read
      Waitms 4
   Next
   Wait 5
Loop

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Bufalo

Bascom Member



Joined: 27 Jan 2017
Posts: 12

PostPosted: Mon Feb 06, 2017 5:52 am    Post subject: Reply with quote

Any news about posted code? does it work? JeezWonder?
Back to top
View user's profile
jeezywonder

Bascom Member



Joined: 19 Jan 2017
Posts: 34
Location: Russia, Vladivostok

russia.gif
PostPosted: Mon Feb 06, 2017 10:04 am    Post subject: Reply with quote

Ok, sorry for late reply, i tested a code that KIMMI gave me with MWS corrections.
I post whole code firstly
Code:
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32
$baud = 9600

Cs Alias Portc.0
Config Portc.0 = Output
Pin_out Alias Pinc.3
Config Portc.3 = Input
Pin_in Alias Portc.2
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output

Declare Sub Read_data_93c46()
Declare Sub Write_data_93c46()
Declare Sub Setup_93c46()

Dim R_data(64) As Word                                      '  1K: 64x16bit
Dim Count As Byte , Count_x As Byte
Dim My_data As Word
Dim My_93c46 As Long
Dim R_93c46 As Byte
R_93c46 = &B00000110
Dim W_93c46 As Byte
W_93c46 = &B00000101
Dim Read_enable As Word  
Read_enable = &B1001100000000000                                  '64x16
Cs = 0

' Enable serial EEPROM    (EWEN):
Call Setup_93c46()

Waitms 50

Do
   For Count = 1 To 64                                      '128 Step 2                              '  1K: 64*16
     Count_x = Count - 1

     'setup sent data
      My_93c46 = W_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
      Shift My_93c46 , Left , 16
      My_data = 4000 + Count_x
      My_93c46 = My_93c46 + My_data                         ' as word
      Shift My_93c46 , Left , 7
      ' Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40

'sent
      Call Write_data_93c46()
      Waitms 4
      Print "W addr + data : " ; Bin(my_93c46)              '  1K: 64*16
      'W addr + data : 101 000001 (xxxxxxxxxxxxxxxx) is data sent

      'setup read data
      My_93c46 = R_93c46
      Shift My_93c46 , Left , 6
      My_93c46 = My_93c46 + Count_x
      Shift My_93c46 , Left , 23
      '   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40
      ' Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40
'read
      Call Read_data_93c46()
      Print "R addr + data: " ; Bin(my_93c46) ; Bin(r_data(count))
     ' R addr + data: 011 0000001 (xxxxxxxxxxxxxxxx) is data read
      Waitms 4
   Next
   Wait 5
Loop
End



Sub Read_data_93c46()
'read from eeprom    3+6       '&B110+address   9 bits
   CS = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40
' read data 2 bytes
   Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40
   Cs = 0
   Waitms 10
End Sub



Sub Write_data_93c46()
' write address and data 2 bytes
   Cs = 1
   Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40          ' Send address and data
   Cs = 0
   Waitms 10
End Sub

Sub Setup_93c46()
' Enable serial EEPROM   1 byte
   Cs = 1
   Shiftout Pin_out , Sck , Read_enable , 1 , 9 , 40         ' Send write enable command
   Cs = 0
   Waitms 10
End Sub

Want to admit that , as im new at bascom it was confusing to get into the code.
First of all, i tried to run a code without any changes, and i got a error during a compile, which was saying that:
Code:
Dim Read_enable As Byte
does not fit into "Byte" because ,
Code:
 Read_enable = &B100110000  
contains 9 bit instead of 8, therefore i chaned Byte to Word. After compline i had a lof of numbers, there are confused me as hell. I attached the image named "The Code without changes".
The next step i did is to deal with "read data" function, i commented a "write data" part, and tried to compile(see the attached image "read data only"), after that i was puzzled why there are so many numbers, noticed that
Code:
 Print "R addr + data: " ; Bin(my_93c46) ; Bin(r_data(count))

"My_93c46" adds to "r_data(count))".
And i tried to separate them like this:
Code:
Print "R addr + data: " ; Bin(my_93c46)

as i got it My_93c46 applies to EEPROM address, becouse when i compile it i get this( see the image " My93c46")
and what i get when tried to compile only "Bin(r_data(count))" - as i got its data that we read from EEPROM, what i get( again see the picture called "Data Read"
As we can see, i didnt get any data, while the code reads address. Any guesses why it doenst work?

Also i have a qestiuons about a code.
What does "4000" applies for? why 4000?
Code:
My_data = 4000 + Count_x

Why do we need to get our EEPROM ready with the codes that the same, as i got "110" its start bit + OP codes, and why in "&B1001100000000000" we needs "1" after "B"
Code:
R_93c46 = &B00000110
Read_enable = &B1001100000000000  
 

Thank you guys for yout help, you make me better at BASCOM, the world would be better if it has more people like you Smile
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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