1st I2C slave program
Hi guys!
I-m trying to simulate a sensor with my SX28 and I2c.
The original sensor, stores the measure·of a distance on the location 42h, its I2c address is 01.
Now i'm tring to reading with another i2c master the momory of my SX28 slave with a number.
I-m using a code provide from Gunther (sorry for spelling), with out any result.
Can be done? i assert:
org $42
distance equ 40·· ;simulating distance
any other suggestion?
Alessandro
I-m trying to simulate a sensor with my SX28 and I2c.
The original sensor, stores the measure·of a distance on the location 42h, its I2c address is 01.
Now i'm tring to reading with another i2c master the momory of my SX28 slave with a number.
I-m using a code provide from Gunther (sorry for spelling), with out any result.
Can be done? i assert:
org $42
distance equ 40·· ;simulating distance
any other suggestion?
Alessandro
Comments
you have already asked me similar questions via eMail...
Without knowing any details of the sensor you like to simulate with an SX acting as an I²C slave, I assume that the original sensor has a set of internal memory locations that can be read out, where one location with address 42h is holding the distance.
Usually, such kind of I²C devices first expect the initialization for a write operation, even when you want to read the device, i.e. you send the device address with bit 0 clear (for write), followed by the internal device address (42h in this case). This simply sets the sensor's internal address pointer but without actually writing something else. Next, the master would generate another start condition (a "running start"), send the device address, this time with bit 0 set (for read). The sensor should acknowledge this, and then send out the data stored at 42h on the following SCL pulses generated by the master until the eight bits are done. The master may send an acknowledge, and continue reading subsequent locations, or send a no acknowledge, followed by a stop condition to terminate the read.
All this is only guesswork as I don't have any information about what sensor you want to simulate.
Anyway, simply saving some value in the SXes RAM at address $42 will not work at all.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
http://www.nxp.com/acrobat_download/applicationnotes/AN10216_1.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Time·─ Space·─ Gravity·─ Darkness·─ Death
This is a small beginig of a bigger project with I2c.
the sensor is the LEGO Ultrasonic·sensor of LEGO MINDSTORM NXT http://shop.lego.com/ByCategory/Product.aspx?p=9846&cn=389&d=292
I·hope·to Know·how·works the I2C, i have read the specifics.
of this sensor i have the sheme, and the memory distribution.
But what i have to modify in the APP25 of your book?
I have done some test.... nothing·
i modify the i2c slave id as request by the lego spec, but i don't see the ACK coming from the SX.
Inside there is a controller, as you say, i have the specifics also of this controller.
SOME HELP?
·
i don't see the·check·of the addres·of the slave·in the program code (ISR).
So·my SX (slave)·doesn't reply "ACK" to the master neither for the first byte.
Then what i have to do? additind another state to the state machine?
Help me...
Alessandro
·
It adds a few states, in that if the master wants more data (by sending ACK), this slave
will stretch the SCL line until it has data ready. Furthermore it supports a broadcast ID
(so this slave recognizes two ID's). I have used this code in a setup where a basic stamp
as I2C master, communicates with 10 SX as I2C slaves.
The I2C VP code is located in codepage_1.
regards peter
In reply to your private email:
I know my code is working and I am sure so is Gunther's.
You should approach this in the following order:
1. Create a program for your master processor to read and write a serial eeprom.
Only when you can reliable read/write the first 64 bytes (because an SX28 cannot hold much more)
continue with step 2. Do not change the master program at this point.
2. Create a program for the SX28 to emulate a serial eeprom of 64 bytes.
Only when the master can reliable read/write the 64 bytes from/to the sx28
continue with step 3.
3. Adjust the master program to read·your sensor.
It should be sufficient to alter the device ID and possible address byte.
Only when the master can reliable read your sensor
continue with step 4. Do not change the master program at this point.
4. Alter the SX28 program to emulate your·sensor.
It should be sufficient to alter the slave ID value and possible address byte reading.
regards peter
Good advice. That's one of the most difficult tasks in the classroom is to convince students to first test a working program without changes. Then make very small incremental changes and save that as a version. Then when it breaks, just go back one version. I can't say I always do that but when I get stuck I remember my masters peering down at me with a wary eye.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College