Guys,
Does anyone have an I2C slave example they'd be willing to share? I've run into a wall with getting a SB70LC working as an I2C slave connected to a Parallax Propeller.
I'm fairly certain I have the I2C master setup properly, as I'm able to communicate with a few other devices (Matrix Oribtal LCD, DS1631, DS1672, 24LC256).
It would appear as though just calling the I2CInit() function while including <i2cmulti.h> would start a task to at least respond to an initial call to the I2C address for a read or write, but Task Scan doesn't show any tasks relating to I2C running.
I'm a little lost. The examples example doesn't appear to do slave operations. Any help would be greatly appreciated...
Thanks,
Scott
I2C Slave Example
Re: I2C Slave Example
I am not sure if the release you are using has the I2C example in it, there is a release coming out very soon which has this for the SB70LC:
C:\Nburn\examples\SB70LC\I2C2Serial
If not you can use the MOD5270 version, it is pretty much identical:
C:\Nburn\examples\MOD5270\I2C2Serial
By default this example should work in multi-mode. It will show you how to read and write as a slave. This driver is interrupt based and there is no need for a separate task. There is are two buffers for slave mode, recieve and write. When you are addressed as a slave the data will be stored or sent from one of these buffers. You then need to call one of the slave functions to read or write to these buffers. The functions are documented in the runtime library pdf:
C:\Nburn\docs\NetBurnerRuntimeLibrary\NetBurnerRuntimeLibraries.pdf
section 12.4 for the I2C slave functions.
-Larry
C:\Nburn\examples\SB70LC\I2C2Serial
If not you can use the MOD5270 version, it is pretty much identical:
C:\Nburn\examples\MOD5270\I2C2Serial
By default this example should work in multi-mode. It will show you how to read and write as a slave. This driver is interrupt based and there is no need for a separate task. There is are two buffers for slave mode, recieve and write. When you are addressed as a slave the data will be stored or sent from one of these buffers. You then need to call one of the slave functions to read or write to these buffers. The functions are documented in the runtime library pdf:
C:\Nburn\docs\NetBurnerRuntimeLibrary\NetBurnerRuntimeLibraries.pdf
section 12.4 for the I2C slave functions.
-Larry
Re: I2C Slave Example
Larry,
Thanks. I should have mentioned, I'm using NNDK 2.3rc4, which shipped with the SB70LC dev kit.
I've reviewed the example and runtime library manual.
I wasn't aware I2C was interrupt driven. I see in the example that the slave TX buffer is filled, and also a routine to read the buffer, but nothing to trigger the send of the slave TX buffer, so should I assume that slave TX buffer is automatically transmitted?
Sorry if these questions seem a little stupid...all my previous NetBurner work has been with serial UARTs, so I2C on this platform is new to me...
Thanks,
Scott
Thanks. I should have mentioned, I'm using NNDK 2.3rc4, which shipped with the SB70LC dev kit.
I've reviewed the example and runtime library manual.
I wasn't aware I2C was interrupt driven. I see in the example that the slave TX buffer is filled, and also a routine to read the buffer, but nothing to trigger the send of the slave TX buffer, so should I assume that slave TX buffer is automatically transmitted?
Sorry if these questions seem a little stupid...all my previous NetBurner work has been with serial UARTs, so I2C on this platform is new to me...
Thanks,
Scott
Re: I2C Slave Example
Hi,
When you are acting as a slave in I2C all communication must be triggered by the bus master. When you want to send data as a slave you must call the function to put data the slave tx buffer. Then when a master device addresses the NetBurner as a slave and asks to read data, it will read the data you put in the tx buffer. You can not tell the bus master to read data if you are a slave. When a master device addresses the NetBurner as a slave and asks to write data, the data will be stored in the slave RX buffer.
If you want to initiate data transfer then you must use the other I2C functions where you are a master device.
-Larry
When you are acting as a slave in I2C all communication must be triggered by the bus master. When you want to send data as a slave you must call the function to put data the slave tx buffer. Then when a master device addresses the NetBurner as a slave and asks to read data, it will read the data you put in the tx buffer. You can not tell the bus master to read data if you are a slave. When a master device addresses the NetBurner as a slave and asks to write data, the data will be stored in the slave RX buffer.
If you want to initiate data transfer then you must use the other I2C functions where you are a master device.
-Larry
Re: I2C Slave Example
Larry,
That much I am aware of...
Here's the code the SB70LC is running...
So, you see I'm initilizing I2C with a slave address of 0x68 (7 MSB's, with LSB being 0 for write, 1 for read). On my other uC, I transmit 0xD1 on the I2C bus (addressing 0x68 as 7 MSB's, and 1 as LSB) to signal the SB70LC I'd like to read. You can see, I've filled the I2C slave TX buffer with the string 'Hello'. All I'm really looking for is an ACK back from the SB70LC at this point (SB70LC should pull SDA low for one clock pulse). However, the SB70LC doesn't appear to be doing it's part by signaling the ACK. After that ACK, I'd then expect the SB70LC to start transmitting the contents of the I2C slave TX buffer until I issue a stop condition on the bus master (pull SDA high, stop SCL clock pulsing).
The same process I'm using to determine if the SB70LC is operating properly, as I mentioned in my first post, works as expected with a number of other I2C devices on the same bus.
I've exhausted all the means I have at my disposal, which is why I was looking for some working I2C slave code...since other devices are working, the only thing I can do now is assume there's something wrong with my code on the SB70LC. From what I can tell, my code is very similar to that in the I2CSerial example...
Scott
That much I am aware of...
Here's the code the SB70LC is running...
Code: Select all
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <taskmon.h>
#include <syslog.h>
#include <i2cmulti.h>
extern "C" {
void UserMain(void * pd);
}
const char * AppName="Syslog_I2C_Test";
void UserMain(void * pd) {
BYTE buff[5];
BYTE *buffptr = buff;
buff[0] = 72;
buff[1] = 101;
buff[2] = 108;
buff[3] = 108;
buff[4] = 111;
InitializeStack();
if (EthernetIP == 0) GetDHCPAddress();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
EnableTaskMonitor();
I2CInit(0x68);
I2CFillSlaveTXBuf(buffptr, 5);
while(1) {
OSTimeDly(TICKS_PER_SECOND);
SysLog("Test %d ", Secs);
}
}
The same process I'm using to determine if the SB70LC is operating properly, as I mentioned in my first post, works as expected with a number of other I2C devices on the same bus.
I've exhausted all the means I have at my disposal, which is why I was looking for some working I2C slave code...since other devices are working, the only thing I can do now is assume there's something wrong with my code on the SB70LC. From what I can tell, my code is very similar to that in the I2CSerial example...
Scott