i2c Slave and COG RAM Access
Hello from the UK
I would like to use a propeller as an i2c Slave. The propeller then receives data written to it and then performs actions depending on the data that it receives. (I'm relatively new to propeller so any response should be couched in terms suitable for the hard of understanding).
The only i2c Slave object in existing is Hippy's :
forums.parallax.com/forums/default.aspx?f=25&m=263375
[noparse][[/noparse]url]
I can kick off the i2c Slave object in a cog. I can write to that slave (using another propeller and existing i2c master objects). How do I access the data accepted by the slave cog (I guess I'm asking how do I access COG ram data).
Any help appreciated.
Eric
I would like to use a propeller as an i2c Slave. The propeller then receives data written to it and then performs actions depending on the data that it receives. (I'm relatively new to propeller so any response should be couched in terms suitable for the hard of understanding).
The only i2c Slave object in existing is Hippy's :
forums.parallax.com/forums/default.aspx?f=25&m=263375
[noparse][[/noparse]url]
I can kick off the i2c Slave object in a cog. I can write to that slave (using another propeller and existing i2c master objects). How do I access the data accepted by the slave cog (I guess I'm asking how do I access COG ram data).
Any help appreciated.
Eric

Comments
If it's in Cog memory you'll need a mechanism to interact with the Cog and have it place its data in Hub memory so it can be accessed by other Cogs. This is going to interfere with the I2C Bus handling itself so it's not recommended. Having the I2C Slave Cog store its data in Hub is probably the best solution.
Added : Looking at the demo code you will find this to start a 16Kx8 RAM, based at $4000 in hub memory ...
i2c_Slave.Start( SCL_PIN, SDA_PIN, DEVICE_ID, $4000, 16*1024 )
You can use @MyArray to supply an array base address instead of $4000, and the array size can be any power of two, so ...
The AiChip_I2cSlave_Slave object uses 1KB of Cog regardless so it's necessary to delete the two lines at ":SaveByteToHub" and the two lines at ":LoadByteFromHub".
It's been a while since I used or looked at the code so apologies if I've remembered anything wrong. Shout if you need any further help.
Post Edited (hippy) : 10/24/2008 8:12:38 PM GMT
No joy. Here is my Master and Slave code respectively, in case I've done something daft.
Additional (I've re-edit (cut-n-paste) but the code is not looking so good when I paste onto the forum - sorry)
I've got to put the nippers to bed now so a reply isn't urgent.
'Master_1 I2C experiment SpinStudio Board CON _CLKMODE = XTAL1 + PLL16x _XINFREQ = 5_000_000 SDA_PIN = 29 SCL_PIN = 28 DEVICE_ID = $E4 OBJ i2cObject : "i2cObject" Pub Main | temp, i i2cObject.init(SDA_PIN,SCL_PIN,False) 'Initialise main i2c WaitCnt( CLKFREQ/100 + CNT ) i2cObject.start WaitCnt( CLKFREQ/100 + CNT ) dira[noparse][[/noparse]0..7]~~ 'LEDs on 0 & 1 showed me that the repeat cycle is working Repeat repeat i from 1 to 500 outa~ i2cObject.Writelocation(DEVICE_ID,i,99,8,8) 'writeLocation(deviceAddress, deviceRegister, !outa[noparse][[/noparse]0] 'i2cDataValue, addressbits,databits). 99 is value to slave WaitCnt( CLKFREQ + CNT ) !outa temp := i2cobject.readlocation(Device_ID,i,8,8) 'deviceAddress, deviceRegister, addressbits, databits If Temp == 99 outa~~ 'LED on Pin 3 tells me If managed to read the slace WaitCnt(CLKFREQ*2 + CNT )'Slave_1 Experiment Using Demo Board CON _CLKMODE = XTAL1 + PLL16x _XINFREQ = 5_000_000 SDA_PIN = 1 SCL_PIN = 0 ID_1 = $E4 SIZE = 1 * 1024 Var Byte Temp byte MyArray[noparse][[/noparse] SIZE ] Obj i2c_Slave1 : "AiChip_I2cSlave_Slave_006" Pub Main Dira[noparse][[/noparse]16..23]~~ if ID_1 => 0 i2c_Slave1.Start( SCL_PIN, SDA_PIN, ID_1, @MyArray, size ) WaitCnt( CLKFREQ / 1000 * 100 + CNT ) Monitor Pub Monitor | i repeat !outa[noparse][[/noparse]16] 'lights an LED to say I'm cycling through the code repeat i from 1 to size Temp := MyArray[i] if temp == 99 '99 is the value I'm trying to write to the slave outa[noparse][[/noparse]17..22]~~ 'LEDs on 17..22 tell me that I have received data on the slave waitcnt(clkfreq*5 +cnt) else outa[noparse][[/noparse]17..22]~ [/i]Post Edited (EricGarlic) : 10/24/2008 9:10:44 PM GMT
did you ever get this figured out? I am working on the same thing and would love to avoid any wheel inventing.
thx
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Searider
Nope. Too busy at work and with the kids to get back to the bench. Give it go and post your findings. Good luck
Eric
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Searider
Eric
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Searider