PDA

View Full Version : reading 2c strings



beto
- 21st December 2004, 16:06
Hi all
I have a little problem with a small routine reading serial eeprom 24c65

The idea is get a string from memory (readi2c command) and put
the data over serial line via serout command

The problem is that the pbp no handle strings very well, the data
I want o read a sinlge line from the memory
the i2c memory looks like this…

org 000
Db “string one”,0
Dc “string two”,0
Db “string …”,0 … and so on.

The last ‘0’ is for know when the string is ending
I have used a 8051 assembler to generate the hex image burned in the eeprom

And my code is..

'Direccion is word all others vars are byte sized

'String is my array

mainloop:

for k = 0 to 50 '50 lines?????????
gosub readline 'read 1 line
hserout [str string\20,10,13] 'print message???
pause 100
next k ' no reset direccion
hserout ["End ",10,13]
pause 3000
goto mainloop


readline:
dirarray = 0 'reset pointer char to 0 (the array)
lineloper:
i2cread porta.2,porta.1,$a0,direccion,[j] 'read char
if (j=0 ) then doneline '0 = end of line
dirarray = direccion
string[dirarray] = j 'make string
direccion = direccion +1 'inc addr
pause 100
goto lineloper 'next char
doneline:
direccion = direccion +1 'skip the enf of line (0)
return 'we done

I have setup the hyperterminal correctly but, I can only see the same line ‘string one’ again , and again
Anyone know, what is wrong….?

Thanks in advance

Dwayne
- 21st December 2004, 16:27
Hello Beto,

B>>
dirarray = 0 'reset pointer char to 0 (the array)
lineloper:
i2cread porta.2,porta.1,$a0,direccion,[j] 'read char
if (j=0 ) then doneline '0 = end of line
dirarray = direccion
string[dirarray] = j 'make string
direccion = direccion +1 'inc addr
pause 100
goto lineloper 'next char
doneline:
direccion = direccion +1 'skip the enf of line (0)
return 'we done
<<
ok...

At first, you set Dirarray to zero.. then the very next 3 lines, you assign it to the value of Direccion.

Thus, when you are loading up your new string called String[dirarray], you are not starting from the beginning... YOu are starting from the "end"

I have no way to check this, but try..

Change it to something like this:

dirarray = 0 'reset pointer char to 0 (the array)
lineloper:
i2cread porta.2,porta.1,$a0,direccion,[j] 'read char
if (j=0 ) then doneline '0 = end of line
string[dirarray] = j 'make string
dirarray=diarray+1;
direccion = direccion +1 'inc addr
pause 100
goto lineloper 'next char
doneline:
direccion = direccion +1 'skip the enf of line (0)
return 'we done


Dwayne

beto
- 21st December 2004, 17:12
Many Tnx Dwayne
really that was the problem, now the code works fine, but born a new problem
Since that I was able to read a line storing it to the array string[X]
i put a 0 value at end of each line AND the array is sized to 20
a string like "the pbp pro is great" is deformed when the next
string is "select one"... the result when i print the string (using serout2)
is "select oneo is great", I think that another char counter must be used or a'clear-array' sub must be implemented but how this is done?

mister_e
- 21st December 2004, 18:34
you don't really need to store it in a array. Why not simply read character and send it one by one. if character is zero skip 1 adress.

How does it sounds to you?

beto
- 21st December 2004, 18:59
Originally posted by mister_e
you don't really need to store it in a array. Why not simply read character and send it one by one. if character is zero skip 1 adress.

How does it sounds to you?

sound logic... but I like send the data string using a single serout comand pheraps a for or while struct (the ram is gold)

beto
- 21st December 2004, 19:03
acording to pbp's manual, a serin2 command may be skiped
in a time if no char is in the rx register, my question is:

how I can sampling two serial port at high speeds (19.200) without data lossing?

mister_e
- 21st December 2004, 19:09
Better using PIC who have 2 internal USARTs... or one internal + SERIN,SERIN2 command. Using internal usart interrupt. BUT not safe at 100%.

Can Also use two SERIN2 with a FlowPin... your harware must control it by itself. NOW you're close to 100% safe.

Dwayne
- 21st December 2004, 19:10
Hello Beto,

Beto>>I think that another char counter must be used or a'clear-array' sub must be implemented but how this is done?<<

Mister-e has in my opinion the best way to accomplish the task. just read each character until End of line comes.

If you still want to use your array of twenty... you can initialize the whole array each time you go into your routine...
Notice I added 3 lines just below your readline...
This is not as good of a way to accomplish what you want as Mister-e's, but I believe it may do the job for you.

something like this:

readline:

for dirarray=0 to 19
string[dirarray]=" "
next dirarray

dirarray = 0 'reset pointer char to 0 (the array)
lineloper:
i2cread porta.2,porta.1,$a0,direccion,[j] 'read char
if (j=0 ) then doneline '0 = end of line
string[dirarray] = j 'make string
dirarray=diarray+1;
direccion = direccion +1 'inc addr
pause 100
goto lineloper 'next char
doneline:
direccion = direccion +1 'skip the enf of line (0)
return 'we done

Dwayne
- 21st December 2004, 19:16
Hello Beto,

Beto>>acording to pbp's manual, a serin2 command may be skiped
in a time if no char is in the rx register, my question is:

how I can sampling two serial port at high speeds (19.200) without data lossing?<<

That I know of, you cannot do such a thing at the *same* time. You can listen to two different ports and if one is triggered, collect that data, then go to listening to both ports again until another trigger is set.


Dwayne

beto
- 21st December 2004, 19:31
Thanks by your answer:
Dwayne
Mister_e
Let me explain my problem:
I have a terminal equipment (8052 based) it send and receive data at 19200bps I use serout/in comand to conect this terminal,
at the other end I have a radio-modem conected to the usart at 9600bps of port of a pic16f877 the terminal has a ascii keyboard and the idea is get data from the terminal and respond to her for displaying that key , but at same time (well no really) I have to check the radio-modem if there is data available, I no want loss a packet data of this modem there is no way to recovery the data since that only is send from a central to radio-modem ONCE, that is the problem thanks again...

Dwayne
- 21st December 2004, 22:07
but at same time (well no really) I have to check the radio-modem if there is data available

Ok then you want the interupt on your Radio. So that it will take over the keyboard. (since the keyboard is not as important)

Mister-e' idea of a interupt and USART should do the trick. The interput will immediately switch to the radio, and receive the data. At the "End of Transmittion" it will finish displaying and return you to the keyboard. The only thing that will happen, is the keyboard may loose a character or you may have to retype the very last character.

Dwayne

mister_e
- 21st December 2004, 23:12
Let me explain my problem:

there's no problem... only opotunity...



I have a terminal equipment (8052 based) it send and receive data at 19200bps I use serout/in comand to conect this terminal,
at the other end I have a radio-modem conected to the usart at 9600bps of port of a pic16f877 the terminal has a ascii keyboard and the idea is get data from the terminal and respond to her for displaying that key , but at same time (well no really) I have to check the radio-modem if there is data available, I no want loss a packet data of this modem there is no way to recovery the data since that only is send from a central to radio-modem ONCE, that is the problem thanks again.

Safe way for the MODEM : using another PIC(let's say PIC16F628) who will only monitor him and store everything in internal or external EEPROM. Once it's done, it will check if the other PIC is available for receiving. In case yes, send data from the last MODEM communication and monitor any other MODEM communication by internal USART interrupt.

beto
- 22nd December 2004, 15:26
Great idea Mister-e!
implementing NOW that stuff(w/2 pics)