From: Meece, C. T <cli...@bp...> - 2007-04-22 14:45:39
|
Hi, I have a robostix card and am trying to talk to it over i2c with the = avrlib library. The sample code provided by avrlib compiles, and I've got it running: [code] Welcome to i2c test! Command> Running I2C memory test (24xxyy devices) Stored data: Pascal is cool!! Received data: a!=A4 Command>Send: test Command>m Running I2C memory test (24xxyy devices) Stored data: test Received data: a!=A4 Command>Receive: Command>Receive: Command> [/code] I can't tell if the output above indicates it is working or not, but = when I use the i2c program from the gumstix, I get this: [code] [root@tortix code]# i2c --verbose 0x50 wb 0 0x111 ERROR: I2cTransfer: ioctl failed: Remote I/O error (121) ERROR: I2cWriteBytes failed: -1 [root@tortix code]# [/code] without a scope, it is hard to tell where this is failing. I have also = paired down the avrlib example code to just the slave receive handler, = to see if it is multi-master issue, but no joy. Looking at the init function in the library, it does this: void i2cInit(void) { // set pull-up resistors on I2C bus pins // TODO: should #ifdef these sbi(PORTC, 0); // i2c SCL on ATmega163,323,16,32,etc sbi(PORTC, 1); // i2c SDA on ATmega163,323,16,32,etc sbi(PORTD, 0); // i2c SCL on ATmega128,64 sbi(PORTD, 1); // i2c SDA on ATmega128,64 // clear SlaveReceive and SlaveTransmit handler to null i2cSlaveReceive =3D 0; i2cSlaveTransmit =3D 0; // set i2c bit rate to 100KHz i2cSetBitrate(100); // enable TWI (two-wire interface) sbi(TWCR, TWEN); // set state I2cState =3D I2C_IDLE; // enable TWI interrupt and slave address ACK sbi(TWCR, TWIE); sbi(TWCR, TWEA); //outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA)); // enable interrupts sei(); } Does that look right for the gumstix+robostix? What about this for device address assignment: void i2cSetLocalDeviceAddr(u08 deviceAddr, u08 genCallEn) { // set local device address (used in slave mode only) outb(TWAR, ((deviceAddr&0xFE) | (genCallEn?1:0)) ); } I've searched on the avrfreaks forums and it seems I'm not the only one = with i2c issues on this platform+library, but I didn't see any = definitive solutions. =20 Any advice?=20 thanks, Cliff =20 Cliff=20 |