reading 2c strings


Closed Thread
Results 1 to 13 of 13
  1. #1
    beto's Avatar
    beto Guest

    Question reading 2c strings

    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

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Post

    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?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Default

    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)

  6. #6
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Question

    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?

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  9. #9
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  10. #10
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Smile

    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...

  11. #11
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Wink

    Great idea Mister-e!
    implementing NOW that stuff(w/2 pics)

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. ds18b20 not reading on 16f676
    By revelator in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2009, 00:20
  3. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 16:21
  4. Pot reading jumping like crazy!!!
    By champion in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th November 2006, 21:24
  5. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts