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?
This was only a suggestion to keep in sync with quite slow software peripherals ( with a few dedicated IIC hardware " bit level " or even no dedicated hardware at all ) and with work to do before replying. Hardware for master take this extended clock as mandatory, but keep in mind that software masters have to test it. This protocol has not been developped for nothing.
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
in the IIC protocol, slaves can be very slow and in fact they can keep the incoming clock signal low for a time to slow the master How wonderful, now we slow the slave and slow the master. Of course if we really do not need to do anything else such as gathering information to transmit? Of course, if the master has gasp interrupt driven hardware IIC only the slave will come to a crawl. So many .....s see "slowing down" as a solution to a problem, this is ridiculous. When we were using the 10MHz PCs many things ran faster than they do today when the so called "programmers" have no concept of time. Erik
I think you have forgotten an important thing in the IIC protocol, slaves can be very slow and in fact they can keep the incoming clock signal low for a time to slow the master. But all software master implementations i've seen are not checking the clock state . for the slave, it is quite simple in the very first instant detecting the clock ( using interrupt ) to fix the clock state for a while until bit treatment is done. I hope this can help.
Software I2C, Hmmm. This weekend I went out to the backyard to light my barbecue. I took my matches, lit it and came back inside. Now I could have taken two sticks instead and rubbed them together for half an hour and lit the fire but matches just seemed like a natural choice. C'mon folks, there's a reason IC companies spend so much time and money implementing certain functions as hardware peripherals in micro cores. It's because sloths like me are too lazy to type all that C code. I wish you the best but it seems to go against the grain. :)
I am not entirely rigid with the chip. However I have access to two bipom board with atmel 89S53. You can replace the 89S53 with a pin compatible P89C66x. The P89C66x is ISP via the serial port, so if the board has a RS232 connection, you will have ISP. Erik
I am not entirely rigid with the chip. However I have access to two bipom board with atmel 89S53. I will ideally like to be able to utilise thses two board since I already have easy access to connect LCD and keypad which I have already interface. The alternative will be to use SPI however, I am using MicroIDE which doesn't recognised the special function register SPDR,SPCR,SPSR. If any one know how this can be done grateful for any assistance. Or maybe I'll try Keil.
Are there any sample code existing for the slave (software) I can look at? I know of no slave software that does not use IIC hardware. What keeps you from replacing the chip with one that has IIC hardware? e.g. the Philips P89C66x series are pin compatible with any standard '51 and have IIC hardware. Erik
The other problem with a software implementation of I2C is that the slave is not in control of the clock. The master sets the clock rate. Since the I2C spec says that the bus is supposed to operate at 100 kHz (for the minimum rate), a conforming master can generate this clock even in hardware, and thus the slave software implementation must be able to keep up at 100 kHz. This speed requires a fairly high clock rate for the 8051 just to sample the clock and data pins and accumulate the data in time. (The lower clocks per instruction cycle devices also help.) I2C devices are allowed to operate at slower clock rates, but only when the master is clocking slower than 100 kHz. This is easy when the software implementation is the master. It simply generates whatever clock it wants to or can do. But when you're stuck with an inflexible master that you can't slow down, you have to beef up the bit-banged slave implementation accordingly. And a device marketed as a separate component might be connected to any master.
I have only two microcontroller on the IIC bus. The master is fine I can read and write to external eeprom. However I am using an interrupt to trigger the slave when the master is ready to send data. This triggering is successful, 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. Are there any sample code existing for the slave (software) I can look at? Grateful for any help!!!
The problem with a software slave IIC is that a slave need to "be alert" all the time. In the case of one slave only on the bus that is not a big problem, but if you have multiple slave that can be quite a hassle. Yes, it is possible to make a soft slave IIC that work with multiple devidces on the bus, but with the plethora of derivatives (noteably Philips and SILabs) with hardware IIC why have the hassle of making something that a) put a heavy load on the processor and b) is non-testatble. Erik
Did you ever get that slave I2C working. I am having a similar problem. My master is definitely working I can write and read data from an external eeprom. However my slave does not seems to respond. NEED HELP!!!
Thank you Franc, I think I got enough information.
No, only SDA. SDA starts I2C activity with START condition, then both are checked inside the EXT1 interrupt routine. This is not a real 'I2C slave' implementation. 89C2051 is hooked on an I2C bus and monitors the communication between uC and serial EEPROM inside a ready made Satellite Receiver. It extract the Channel number and drives an Antenna Dish accordingly. Interrupt routine is written in assembly. I'm afraid that completely interrupt based would not be fast enough because of interrupt latency.
Hi Franc, Did you connect EXT0 to SCL? Or just check both SCL and SDA inside the EXT1 interrupt routine? I have thought about the interrupt driven scheme. The interrupt routine shall be written in assembler to get maximum speed, right? What's the maximum I2C speed that your MPU can handle? < 20KHz? Did you use any handshaking like keeping the SCL in 0 to avoid overflow when processing?
View all questions in Keil forum