#include "i2clib/i2c.h"
#include <cstdio>
#include <unistd>
int main() {
char lightshow = 0x01; //0x80
int retval = 0;
printf("Starting I2C test \n\n ");
if (!i2c_Initialize(I2CIRQ_DISABLE)) {
perror("Can't open I2c");
return -5;
}
if( i2c0_SetSpeed(I2CMODE_STANDARD, 100000L) !=0 ){
perror("Couln't set i2c speed\n");
}
do {
printf("Blink \n\n ");
//START with address 0x40 to write 1 byte
i2cmaster_StartN(0,0x40, I2C_WRITE, 1);
i2c0master_WriteLast(lightshow); //set SRF command register
usleep(6000); //wait 3000ms
lightshow <<= lightshow;
} while (true); //press ctr+c to quit
i2c_Close();
return retval;
}
maestro wrote:
- Code: Select all
......
i2cmaster_StartN(0,0x40, I2C_WRITE, 1);
i2c0master_WriteLast(lightshow);
......
......
if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
{
printf("START fail (%s)...try again\n", roboio_GetErrMsg());
if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
{
printf("START fail again (%s)\n", roboio_GetErrMsg());
i2c_Close();
return 0;
}
}
if (!i2c0master_WriteN(lightshow))
{
printf("WRITE fail (%s)\n", roboio_GetErrMsg());
i2c_Close();
return 0;
}
......