This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Software I2C in slave mode

I want to simulate an I2C slave device using a generic 8051 MPU which doesn't have hardware I2C(not like 80C552). I know it is easy to implement software simulated I2C in master mode, but I want to turn my 8051 MPU to be a slave device. How can?

Parents
  • Hi Cal,

    Just clarify what you ment by "however the data received is DEFINITELY not being sent.
    I think the problem may be timing between the transmitting and receiving or the my method of receiving the data."

    If your slave is triggering on the START condition then from the I2C protocol "Data on the SDA pin may change only during SCL low time periods". So if you look at the following it should hopefully help:-

    jb SCL,$ ;get past "START" condition
    
    REPT 8   ;repeat block get all 8 bits of data
    jnb SCL,$ ;wait for clock to go high
    mov c,SDA ;read data transmitted MSB first
    rrc a     ;and save it
    ENDM
    

    This code should be fast enough to work at 400KHz, I have written a transmitter and had to insert nop's to slow it down.

    Note that above i havent bothered with the 9th bit - the ACK/NACK which you may want to consider and also from the I2C protocol "Data changes during SCL high periods will indicate a start or stop condition" so you will have to add extra code to decide wether it is then next byte or the end of the message if that is important to you.

    Mark.

Reply
  • Hi Cal,

    Just clarify what you ment by "however the data received is DEFINITELY not being sent.
    I think the problem may be timing between the transmitting and receiving or the my method of receiving the data."

    If your slave is triggering on the START condition then from the I2C protocol "Data on the SDA pin may change only during SCL low time periods". So if you look at the following it should hopefully help:-

    jb SCL,$ ;get past "START" condition
    
    REPT 8   ;repeat block get all 8 bits of data
    jnb SCL,$ ;wait for clock to go high
    mov c,SDA ;read data transmitted MSB first
    rrc a     ;and save it
    ENDM
    

    This code should be fast enough to work at 400KHz, I have written a transmitter and had to insert nop's to slow it down.

    Note that above i havent bothered with the 9th bit - the ACK/NACK which you may want to consider and also from the I2C protocol "Data changes during SCL high periods will indicate a start or stop condition" so you will have to add extra code to decide wether it is then next byte or the end of the message if that is important to you.

    Mark.

Children
No data