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?
Philips has 2 appnotes (433 and 463) on this, they can be found <a href="" target="_blank">http://www.semiconductors.philips.com/products/standard/microcontrollers/products/index.html">here</a> Erik Ps do not ignore because it states specific derivatives such as 751, they ARE '51 processors.
Thanks Eric, I know how to deal with slave I2C with the on-chip I2C controller. But if there is no on-chip I2C controller, how can? It seems difficult to implement. First the 8051 speed must be high (> 30M), and the I2C speed shall be slowed down so that software can simulate the I2C. Anyone has experience on it?
Hi, you can check your code with my I²C simulation (works with µVision2) (http://www.c51.de/c51.de/Dateien/uVision2DLLs.php3?Spr=EN). You can find also a I²C library http://www.c51.de/c51.de/Dateien/Liste.php3?Edit=0&showHerst=1&showArt=1&RubrikID=15 and search I2c_lib (suchen == search) Michael
Thanks Michael, I've already known your simulation DLL. You did a great job. Yes, your I2C simulation works in slave mode, but your I2c_lib only works in master mode, right? What I want is to let my 8051 MPU work in slave mode, so that other MPU, or PC can send data to it via I2C. Anyway, it is not critical, I can use another I2C device like I2C memory to store the intermedial data, or use UART to transfer data. But I'm interested in finding a way that costs little. That's why I don't want to use on-chip I2C controller or UART or third I2C device.
Hi Archie, yes it's only for slave communication, sorry. Michael
I have done that. My 89C2051 was running at 24MHz. I used EXT1 interrupt to trigger on hi to low transition of SDA line. This was an I2C start event trigger. Then actual I2C traffic was checked in polling mode inside EXT0 interrupt routine which exits when the stop condition is met. I was 'listening' to the SatReceiver I2C bus to extract channel number for addon Sat Dish positioning system.
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?
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.
Thank you Franc, I think I got enough information.
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!!!
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
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 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.
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
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.