PDA

View Full Version : Problem with I2C EEPROM addressing



Atom058
- 1st August 2008, 19:38
Hello - I have a strange problem when trying to access an EEPROM at a certain address. I have a string of five 24LC256 EEPROMs all sharing the same clock and data line. On the first 4, I am storing the position of 4 servos with the position value converted to a byte-sized variable. On the last one, I am storing the state of a relay (1 or 0). The EEPROMs are addressed 000, 001, 010, 011 and 100. I have no problem reading and writing to the first 3 EEPROMs and the last one, but for some reason, I can not read or write to the 4th EEPROM (011). I have tried swapping EEPROMs around and have determined that there is something to do with that address. My code is pretty straight forward - record mode = read the positions of the 4 servos and relay convert to byte-size (servos) and store the data. Playback mode = read the data convert it to word-sized numbers (for servos) and send it out. The same code is used for all 4 servos. 1, 2 and 3 work fine, 4 just pegs out during playback. The servo #4, when under manual control, responds fine. Anyone have any idea what my problem could be? Attached is a drawing showing my EEPROM layout. I thought it might be a timing issue but why does it only affect #4 and not #5?

PBP 2.5 and 877A PIC.
Here are some code snipetts:

Posit var word
Posit1 var word
Posit2 var word
Posit3 var word
Posit4 var word
PVal var byte

'EEPROM 1 will contain posit data for Servo 1
EChip1W CON %10100000 'Write mode for EEPROM 1
EChip1R CON %10100001 'Read mode for EEPROM 1

'EEPROM 2 will contain posit data for Servo 2
EChip2W CON %10100010 'Write mode for EEPROM 2
EChip2R CON %10100011 'Read mode for EEPROM 2

'EEPROM 3 will contain posit data for Servo 3
EChip3W CON %10100100 'Write mode for EEPROM 3
EChip3R CON %10100101 'Read mode for EEPROM 3

'EEPROM 4 will contain posit data for Servo 4
EChip4W CON %10100110 'Write mode for EEPROM 4
EChip4R CON %10100111 'Read mode for EEPROM 4

'EEPROM 5 will contain data for Relay
EChip5W CON %10101000 'Write mode for EEPROM 5
EChip5R CON %10101001 'Read mode for EEPROM 5

Record Mode Code Snipett---
gosub ReadPot1
pulsout servo1, posit1
pause 5

gosub ReadPot2
pulsout servo2, posit2
pause 5

gosub ReadPot3
pulsout servo3, posit3
pause 5

gosub ReadPot4
pulsout servo4, posit4
pause 5

if recordflag = 1 then 'store data
posit = (posit1 * 23) / 100 'convert to a value < 255
pval = posit 'put into a byte variable
I2CWRITE DPIN, CPIN, EChip1W, Addr, [PVal] 'write it out

posit = (posit2 * 23) / 100
pval = posit
I2CWRITE DPIN, CPIN, EChip2W, Addr, [PVal]

posit = (posit3 * 23) / 100
pval = posit
I2CWRITE DPIN, CPIN, EChip3W, Addr, [PVal]

posit = (posit4 * 23) / 100
pval = posit
I2CWRITE DPIN, CPIN, EChip4W, Addr, [PVal]

if RelaySw = 1 then
pval = 1
else
pval = 0
endif
I2CWRITE DPIN, CPIN, EChip5W, Addr, [PVal]
addr = addr + 1
endif

PlayBack Mode Code Snipett---
high PlayLED
read 16, Lastaddr.byte0
read 17, lastaddr.byte1

for addr = 1 to lastaddr
i2cread dpin, cpin, echip1r, addr, [pval]
posit = pval * 4 'multiply by 4.03 to convert back to word
posit = posit + ((pval * 3) / 100)
pulsout servo1, posit
pause 5

i2cread dpin, cpin, echip2r, addr, [pval]
posit = pval * 4
posit = posit + ((pval * 3) / 100)
pulsout servo2, posit
pause 5

i2cread dpin, cpin, echip3r, addr, [pval]
posit = pval * 4
posit = posit + ((pval * 3) / 100)
pulsout servo3, posit
pause 5

i2cread dpin, cpin, echip4r, addr, [pval]
posit = pval * 4
posit = posit + ((pval * 3) / 100)
pulsout servo4, posit
pause 5

i2cread dpin, cpin, echip5r, addr, [pval]
if pval = 0 then
low Relay
low RelayLED
else
high Relay
high RelayLED
endif

if SSRecBtn = 1 then
low Relay
low RelayLED
low PlayLED
pause 500
goto Start
endif
next

skimask
- 1st August 2008, 20:30
Short of a bad solder joint, I don't see anything wrong at a quick look.
Swap out a few chips and see what happens. Double check your joints.
Slow down the oscillator and see what happens.

(And on a side note, post all your code if you can. I can see room for a bunch of improvements that can be made in your code, streamlining it and all. And I'm not talking about MY standard 'colon-ization' stuff :) )

Darrel Taylor
- 1st August 2008, 21:56
On the 24LC256, Pin1 (A0) is the low order bit. You have them reversed in the picture.

Red is the actual addresses.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2794" />

Atom058
- 2nd August 2008, 00:38
That was IT!!!! You guys are so awesome!!! Thanks! It works perfectly now... Funny how that one was the only one where it mattered that I had it backwards. I had the right addresses (except one) but they were not assigned to the EEPROMs that I thought they were...

Thanks again!

skimask
- 2nd August 2008, 02:48
Aw crap! I poured over that schematic and missed it...
Chalk another one up for DT...

Darrel Taylor
- 2nd August 2008, 05:50
I poured over that schematic ...

What a coincidence! &nbsp;I poured a beer while looking over that schematic.

Maybe it helped? :D
<br>

Dave
- 4th August 2008, 13:25
Atom058, Why all the hardware? Why not just use an 24LC1025?

Dave Purola,
N8NTA

Atom058
- 5th August 2008, 19:57
Dave - Yes, I could have done that, but I have a bunch of these and size was not a problem. I will certainly consider that for the future... Thanks!

sergio
- 30th October 2009, 18:50
[QUOTE = Atom058; 60240 Olá] - Eu tenho um problema estranho ao tentar acessar uma EEPROM em um determinado endereço. Eu tenho uma seqüência de cinco 24LC256 EEPROMs todos compartilhando o mesmo relógio e linha de dados. Na 4 primeiro, eu estou armazenando um POSIÇÃO DE 4 servos POSIÇÃO COM O valor convertido para um byte de tamanho variável. Na última, eu estou armazenando o estado de um relé (ou 1 0). O EEPROMs abordadas são 000, 001, 010, 011 e 100. Não tenho nenhum problema de leitura e escrita para os 3 primeiros EEPROMs ea última, mas por alguma razão, eu não consigo ler ou gravar uma EEPROM 4 (011). Tentei trocar EEPROMs ao redor e ter determinado que há alguma coisa ver um com esse endereço. Meu código é bastante simples - modo de gravação ler = as posições dos servos e revezamento 4 conversor para byte de tamanho (servos) os dados e Armazenar. Modo de reprodução = ler os dados converte-lo para uma palavra-de tamanho (número de servos) e enviá-lo para fora. O mesmo código é utilizado para todos os 4 servos. 1, 2 e funcionam bem 3, apenas 4 pinos para fora durante a reprodução. O servo # 4, quando sob o controle manual, responde muito bem. Alguém tem alguma idéia do que poderia ser meu problema? Em anexo é um desenho mostrando o layout do meu EEPROM. Eu pensei que poderia ser um problema de tempo, mas porque é que só afetam # 4 e # 5, não?

* PBP PIC 2,5 e 877A.
* Aqui estão alguns snipetts Código:

**** Var palavra Posit
**** Posit1 palavra Var
**** Posit2 palavra Var
**** Posit3 palavra Var
**** Var palavra Posit4
**** Var PVal byte

**** "EEPROM 1 CONTERA Dados sobre POSIÇÃO Servo de 1
****% EChip1W CON 10100000 'modo de gravação para EEPROM 1
**** EChip1R% CON 10100001 'modo de leitura para EEPROM 1

**** "EEPROM 2 Irá Conter dados sobre POSIÇÃO de Servo 2
****% EChip2W CON 10100010 'modo de gravação para EEPROM 2
**** EChip2R% CON 10100011 'modo de leitura para EEPROM 2

**** "EEPROM 3 CONTERA Dados sobre POSIÇÃO de Servo 3
****% EChip3W CON 10100100 'modo de gravação para EEPROM 3
**** EChip3R% CON 10100101 'modo de leitura para EEPROM 3
****
**** "EEPROM 4 Contém dados sobre POSIÇÃO de Servo 4
****% EChip4W CON 10100110 'modo de gravação para EEPROM 4
**** EChip4R% CON 10100111 'modo de leitura para EEPROM 4
****
**** "EEPROM 5 Irá Conter dados para Relay
****% EChip5W CON 10101000 'modo de gravação para EEPROM 5
**** EChip5R% CON 10101001 'modo de leitura para 5 EEPROM

* Modo de Gravação Código Snipett ---
**** Gosub ReadPot1
**** PULSOUT servo1, posit1
**** Pausa 5
********
**** Gosub ReadPot2
**** PULSOUT servo2, posit2
**** Pausa 5
********
**** Gosub ReadPot3
**** PULSOUT servo3, posit3
**** Pausa 5
********
**** Gosub ReadPot4
**** PULSOUT servo4, posit4
**** Pausa 5

**** Se recordflag = 1 then 'dados armazenam
******** Posicao = (posit1 * 23) / 100 'converter um valor para <255
******** Pval byte = posit 'colocar em uma variável
******** I2CWRITE DPIN, CPIN, EChip1W, Addr [PVal] 'write it out
********
******** Posicao = (posit2 * 23) / 100
******** Pval = posit
******** I2CWRITE DPIN, CPIN, EChip2W, Addr [PVal]
********
******** Posicao = (posit3 * 23) / 100
******** Pval = posit
******** I2CWRITE DPIN, CPIN, EChip3W, Addr [PVal]
************
******** Posicao = (posit4 * 23) / 100
******** Pval = posit
******** I2CWRITE DPIN, CPIN, EChip4W, Addr [PVal]
************
******** Se RelaySw = 1 then
************ Pval = 1
******** Diferente
************ Pval = 0
******** Endif
******** I2CWRITE DPIN, CPIN, EChip5W, Addr [PVal]
******** Addr = addr + 1
**** Endif

* Modo de Reprodução Código Snipett ---
**** Alta PlayLED
**** Ler 16, Lastaddr.byte0
**** Ler 17, lastaddr.byte1
****
**** Addr = 1 para um lastaddr
******** I2cread dpin, CPIN, echip1r, addr, [pval]
******** Posit = pval * 4 'multiplicar por 4,03 para converter de volta para o Word
******** POSIÇÃO = posicao + ((pval * 3) / 100)
******** PULSOUT servo1, postular
******** Pausa 5
********
******** I2cread dpin, CPIN, echip2r, addr, [pval]
******** Posit = pval * 4
******** POSIÇÃO = posicao + ((pval * 3) / 100)
******** PULSOUT servo2, postular
******** Pausa 5
****************
******** I2cread dpin, CPIN, echip3r, addr, [pval]
******** Posit = pval * 4
******** POSIÇÃO = posicao + ((pval * 3) / 100)
******** PULSOUT servo3, postular
******** Pausa 5

******** I2cread dpin, CPIN, echip4r, addr, [pval]
******** Posit = pval * 4
******** POSIÇÃO = posicao + ((pval * 3) / 100)
******** PULSOUT servo4, postular
******** Pausa 5
**************
******** I2cread dpin, CPIN, echip5r, addr, [pval]
******** Pval Se = 0 então
************ Baixo Relay
************ Baixa RelayLED
******** Diferente
************ Relé de alta
************ Alta RelayLED
******** Endif
********
******** Se SSRecBtn = 1 then
************ Baixo Relay
************ Baixa RelayLED
************ Baixa PlayLED
************ Pause 500
************ Goto Start
******** Endif
**** Próxima QUOTE [/]
Olá
iria me ajudar

que registram o movimento do servo-4

Tenho um programa em PBASIC
Eu quero converter para PICBASIC Pro
ser capaz de me ajudar
coloque bacalhau em um novo tópico

pesquisar

Acetronics2
- 30th October 2009, 20:01
Nice translation of post #1 ... ( Brazilian ??? )

But where is the problem ???

remove the "stars" or what ???

Sorry, but help needed for translation : Just French ,English, German and Italian spoken ... Castejano only under torture.

Alain

Acetronics2
- 31st October 2009, 09:59
Tenho um programa em PBASIC
Eu quero converter para PICBASIC Pro



Tanslation :
I have a program in PBASIC I want to convert it for PICBASIC


This program ALREADY is a PicBasicPro program ...

What are you looking for ???

Alain

rsocor01
- 31st October 2009, 18:21
What's the matter ???
Nice translation of post #1 ... ( Brazilian ??? )

Acetronics,

I really hate to correct you on this one, but in Brazil they don't speak "Brazilian" they speak Portuguese.

Robert

Acetronics2
- 31st October 2009, 19:27
hi, Robert

My dictionnary makes notable difference between Brazilian Portuguese and European Portuguese ... ( 2 different files ...)

Just like Urugayan and Argentinian Spanish ... "Spanish" also called " Castejano ", BTW. ... that Spanish tourists couldn't understand while I went there for Working :

I had to translate from Spanish to English, my accompanist Engineer from English to Castejano and vice versa ... Humour !!!


sooo ... where the truth, in this world of supra-culture ???


Alain

sergio
- 3rd November 2009, 02:48
my friends coming back to the subject
1 in this link: http://www.robodyssey.com/resources/Code/NPicservorecorder.htm program records the trez movements (in servo rc)
2 I want to compile in (pic basic pro)
3 have an alteration in (portA)
4 as to make the alteration
5 necessary of aid to modify the program of (pbasic) for (pic basic Pro)
6 in Brazil we say Portuguese who and well different of protugues spoken in portugual (Europe)

Darrel Taylor
- 3rd November 2009, 03:17
This page may help you to convert a Picbasic program to PicBasic Pro.
It's not too hard.

http://www.melabs.com/support/pbc2pbp.htm
<br>