Shop OBEX P1 Docs P2 Docs Learn Events
I2C virtual peripheral — Parallax Forums

I2C virtual peripheral

AlessandroAlessandro Posts: 26
edited 2008-04-17 20:28 in General Discussion
Hi guys how are you?
·I'm fine, i'm just work around the I2C virtual peripheral to comunicate with·the LEGO ULTRASONIC sensor (of NXT).

I have some problem...

I'm trying to reproduce the normal I2C·comunication of the NXT brick with an SX28.

It follows the I2C standard. but in the comunication there is a byte (the third) that i can't send with sx.

I need to send a simple byte: a "00000011" and then the slave (the ultrasonic sensor) has to respond me with an ack.

Can Anybody help me?

Thanks a lot!

Alessandro Italy

Comments

  • BeanBean Posts: 8,129
    edited 2008-04-02 13:06
    Alessandro,
    Please post what you have so far.
    It should be just I2CSEND SDA, %00000011

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • AlessandroAlessandro Posts: 26
    edited 2008-04-02 13:33
    I'm using Scenix Virtual peripheral, i2cm_vp.src .

    I'm programming in Assembler
    but if you have some other working in SX/B i'm happy to use it.

    Next step is to use the SX as slave connected to the NXT brick (that is only master in I2C comunication)
  • BeanBean Posts: 8,129
    edited 2008-04-02 14:05
    Oh I missed that you were using the VP.
    Post the code anyway.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • AlessandroAlessandro Posts: 26
    edited 2008-04-03 09:36
    This is my MAIN (the rest of VP in not changed appart for the slaveid and the isr_period)

    I need to Send the byte in this order (1° slaveid, address of memory, $03, and then i need to read the result of a distance misure by Lego Ultrasonic Sensor.

    Can anybody help? or send me the routin in SXB?



    main _bank I2CM
    mov I2CM_address,#slave_adr ; set address of slave to read.
    _bank VARS ; clear read and write pointers
    clr read_adr
    clr write_ptr
    mov read_adr,#$42

    I2C_read
    _bank VARS
    mov w,read_adr
    _bank I2CM
    mov I2CM_data_0,w ; load send register with data address
    call @I2CM_wait_not_busy ; wait for I2CM state machine to enter idle state
    call @I2CM_send_byte ; send 'want to read' and bank addess to i2c slave
    call @I2CM_wait_not_busy ; wait for I2CM state machine to enter idle state
    call @I2CM_get_byte ; Gets the byte from slave and returns it in w
    snb I2CM_NACK
    jmp got_NACK ; indicate no NACK by entering never ending loop
    test w ; check for null character read
    ;jz main ; null char, end of string...restart
    ;mov recv_char,w ; save received character
    ;cjne recv_char,#'S',bad_data ; used to confirm valid recieved matches stored data


    Thanks a lot.

    Alessandro (Italy)
  • AlessandroAlessandro Posts: 26
    edited 2008-04-04 12:59
    the sequence i'd like to reproduce is:
    Slaveid( in my case $02), address memory of slave (in my case $42), $03, and then i'd like to read the result of measurament.
    Any idea of prolem in my code?

    Thanks
    Alessandro (Italy)
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-04-04 16:34
    Alessandro,

    I only see one call to I2CM_send_byte but you describe a need to send three bytes before you perform a read operation.· Where are you trying to send each of the bytes you describe?

    ·- Sparks
  • AlessandroAlessandro Posts: 26
    edited 2008-04-04 19:24
    Hi Sparks-R-Fun

    In the first lines, i·wrote the SLAVEid and the address of slave:

    mov I2CM_address,#slave_adr······················ ; set address of slave to read.
    _bank VARS ; clear read and write pointers
    clr read_adr
    clr write_ptr
    mov read_adr,#$42
    If you see with oscilloscope, you will find that this two byte are send·on the SDA line of I2C with one call.
    The third byte is sent with another call,that i Added:

    _bank·I2CM
    ··mov·I2CM_data_0,#$03··;load send register with data address
    ··call·@I2CM_wait_not_busy··; wait for I2CM state machine to enter idle state
    ··call·@I2CM_start_write··; wait for I2CM state machine to enter idle state
    ··call·@I2CM_write···; send 'want to read' and bank addess to i2c slave
    ··call·@I2CM_wait_not_busy··; wait for I2CM state machine to enter idle state
    ··;call·@I2CM_get_byte

    ··;snb·I2CM_NACK
    ··;jmp·got_NACK···; indicate no NACK by entering never ending loop
    ··test·w····; check for null character read
    ··;jz·main····; null char, end of string...restart
    ··mov·recv_char,w···; save received character
    ··;cjne·recv_char,#'S',bad_data··; used to confirm valid recieved matches stored data

    The problem is that between the first 2 byte and the third there is (seen with oscilloscope) another byte that it is not on the· code i write.

    In this way the LEGO NXT sensor will not work.

    What are the problems in my code?
    Has someone the SASM traslation of this assembly virtual peripheral?

    Thanks for answer.
    Alessandro
  • AlessandroAlessandro Posts: 26
    edited 2008-04-17 20:28
    ANY who uses the i2c virtual peripheral..... please....

    Alessandro Leopardi
Sign In or Register to comment.