View previous topic :: View next topic |
Author |
Message |
mushaba
Joined: 08 Feb 2013 Posts: 5 Location: Thessaloniki
|
Posted: Fri Feb 08, 2013 11:58 pm Post subject: Greetings ! Help Needed with I2C and 24C16A |
|
|
Hello!
My name is Fotis, i come from Greece and in very very new to BASCOM.I'm used to write assemby code and when i found out about BASCOM i was so happy.
Now,i'm trying to interface a ATINY2313 with
a card reader http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/32320-SmartCardReader-v1.0.pdf
and an eeprom card http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/IS24C16A-Datasheet.pdf
I read in the Application Notes a lot of examples and i modified one so i can write a byte into the card and then read id back,this is my very first BASCOM code please excuse all my mistakes
Code: |
'*************** Register MCU,Oschillator and baud *************************************)
$regfile = "2313def.dat" 'using ATiny2313
$crystal = 4000000 'using 4 MHz Crystal
$baud = 9600 ' use 9600 baud rate (8-N-1)
'***************************** Define Ports ********************************************)
Portd = &B0000_0000
Ddrd = &B1100_1111 ' I2C pins as inputs
'*************************** Define I2C Pins *******************************************)
Config Scl = Portd.4 ' Clock Pin 8 (PD4)
Config Sda = Portd.5 ' Clock Pin 9 (PD5)
'************************* Subroutines Declare *****************************************)
Declare Sub Card_wr(byval Adres As Byte , Byval Value As Byte )
Declare Sub Card_rd(byval Adres As Byte , Byval Value As Byte )
'******************* Working variables and Constants ************************************)
Dim B1 As Byte , Adres As Byte , Value As Byte 'dim byte
Const Addressw = &B10101110 '1010 (standard for IS24C16A) 111 (slave adress) 0 write
Const Addressr = &B10101111 '1010 (standard for IS24C16A) 111 (slave adress) 1 read
'******************************* Main Program *****************************************)
Call Card_wr(250 , 1) 'Calling Card Write Subroutine,write to adress 1 the number 1
Call Card_rd(250 , Value) 'Calling Card Read Subroutine,read the value of adress 1
'Send to COM port the string
Print Str(value)
End
'******************************* SUBROUTINES *****************************************)
'Card Write
Sub Card_wr(byval Adres As Byte , Byval Value As Byte)
I2cstart 'Generate Start Condition
I2cwbyte Addressw 'Send Slave Adress and write bit 10101110
I2cwbyte Adres 'Send Desired Adress to write
I2cwbyte Value 'Sends Value to write
I2cstop 'Generate Stop condition
Waitms 100 'wait for 100 milliseconds
End Sub
'Card Read
Sub Card_rd(byval Adres As Byte , Value As Byte)
I2cstart 'Generate Start Condition
I2cwbyte Addressw 'Send Slave Adress and write bit 10101110
I2cwbyte Adres 'Send Desired Adress to write
I2cstart 'Generate Start Condition
I2cwbyte Addressr 'Send Slave Adress and read bit 10101111
I2crbyte Value 'Read byte
I2cstop 'Generate Stop Condition
Waitms 100
End Sub |
I compile it ,program it via STK500 but always i get the same thing as readback 0.The Serial port is configured to 9600,8,N,1 connected to a Max232 and the to the Com port of my PC,using Terminal.
Where am i go wrong?
How can i write a word to a memory adress and then read it back?
Awaiting for your replies
Please excuse my poor English
Fotis |
|
Back to top |
|
|
PeterM
Joined: 09 Jun 2008 Posts: 118
|
Posted: Sat Feb 09, 2013 2:50 pm Post subject: |
|
|
Fotis
Are you trying to comunicate with the Smart Card Reader (obviously you are using some type of Smart Card?) ?
or EEPROM ?
I ask because if you want to talk to the EEPROM it requires I2C , if you want to play with the Smart Card Reader you talk to it by
Serial, though you need to add some circuitry like Clock Signal to make the Smart Card work. _________________ Peter |
|
Back to top |
|
|
mushaba
Joined: 08 Feb 2013 Posts: 5 Location: Thessaloniki
|
Posted: Mon Feb 11, 2013 10:08 am Post subject: |
|
|
Hello Peter thanks for your reply and excuse me for my delayed answer.
Well as you can see this "looks like" a smart card but it is a I2C eeprom..The circuitry is allready made (complete with psu,mcu,max232 and i attached an lcd 2*16)
I compiled a few codes like this one ( http://www.mcselec.com/index.php?option=com_content&task=view&id=103&Itemid=57 ) i found on the site and it works fine.
As i said im very,VERY new to bascom and i cannot write my own code so i took great examples i found online and tried to modified them.
My fisrt obsticle was the adressing,all people said that you need high and low adress,in the manufacture pdf the say nothing about high or low adress,so im not getting things right and i never used an external epprom before,i dont know how its made exactly to understand the way it works (for adressing).
Yes it is an I2C eeprom and today if i can resolve the high-low adressing issue i have i should be able to program it as i want.
My project is to write a name on the card and also some "units" to countdown the working hours.
The card reader is not like phoenix/smartmouse that has a serial port to send and receive from an 7816 card.It's just a card reader with half the pinout (only needed DATA,CLOCK,RESET,Vcc plus GND and a contact that reads if the card is in or out.
Can you explain me how should i use the adress bytes?
The code i wrote makes sense?
Awaiting for your reply
Fotis _________________ Be Quick or Be Dead |
|
Back to top |
|
|
PeterM
Joined: 09 Jun 2008 Posts: 118
|
Posted: Wed Feb 13, 2013 9:31 am Post subject: |
|
|
Fotis
Ok, just noticed the Smart Card connector is only a connector and no other components.
You should look at some of the Bascom samples File - Open - Sample , then look in the I2C folder.
Edit: Mark, possibly move this Thread elsewhere? _________________ Peter |
|
Back to top |
|
|
mushaba
Joined: 08 Feb 2013 Posts: 5 Location: Thessaloniki
|
Posted: Thu Feb 14, 2013 12:02 am Post subject: |
|
|
Well i found the solution to my problem with a "for-next" loop.Also this card hasnt high and low adresses,only one 8-bit adress.
Thanks anyway for trying to help me! _________________ Be Quick or Be Dead |
|
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
|
|