Hello,
Quite new on MQX, I'm using the version 3.8 and I have problems in I2C, sending or receiving more than one byte.
I tried I2C using polling and interrupt, having same bad results.
I tried adding controls in order to check if functions calls return wrong values, but all seems ok.
With oscilloscope I can seen very well the bytes sent, but only one.
I've read this post and tried to do the changes on the 3.8 version but MQX do not complie, some errors in some defines.
I will be happy if someone can help.
Here I copy the driver I'm trying to program:
MQX_FILE_PTR i2c_port;
/*.........................................................................*/
void I2C_Init()
{
uint_32 param;
uint_8 mem;
i2c_port = fopen ("ii2c0:", NULL);
ioctl (i2c_port, IO_IOCTL_I2C_SET_MASTER_MODE, NULL);
param = 100000;
ioctl (i2c_port, IO_IOCTL_I2C_SET_BAUD, ¶m);
// This is just to check the line
fwrite (&mem, 1, 0, i2c_port);
ioctl(i2c_port, IO_IOCTL_FLUSH_OUTPUT, ¶m);
ioctl(i2c_port, IO_IOCTL_I2C_STOP, NULL);
}
/*.........................................................................*/
int I2CWriteToSlave(uint_16 address, unsigned char *mess, unsigned int len)
{
uint_8 result;
/* Set the destination address */
ioctl (i2c_port, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &address);
/* Write 'len' bytes of data */
fwrite (&mess, 1, len, i2c_port);
fflush (i2c_port);
/* Send out stop */
ioctl (i2c_port, IO_IOCTL_I2C_STOP, NULL);
return 1;
}
/*.........................................................................*/
int I2CReadFromSlave(uint_16 address, unsigned char *mess, unsigned int len)
{
uint_8 result;
//Set the I2C destination address
ioctl (i2c_port, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &address);
//Set how many bytes to read
ioctl (i2c_port, IO_IOCTL_I2C_SET_RX_REQUEST, &len);
//Read n bytes of data and put it into the recv_buffer
fread (&mess, 1, len, i2c_port);
//Wait for completion
fflush (i2c_port);
//Send out stop
ioctl (i2c_port, IO_IOCTL_I2C_STOP, NULL);
return 1;
}
/*.........................................................................*/
int I2CReadAfterWrite(uint_16 address, unsigned char *tmess, unsigned int tlen,
unsigned char *rmess, unsigned int rlen)
{
uint_8 result;
//Set the I2C destination address
ioctl (i2c_port, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &address);
fwrite (&tmess, 1, tlen, i2c_port);
//Wait for completion
fflush (i2c_port);
//Do a repeated start to avoid giving up control
ioctl (i2c_port, IO_IOCTL_I2C_REPEATED_START, NULL);
//Set how many bytes to read
ioctl (i2c_port, IO_IOCTL_I2C_SET_RX_REQUEST, &rlen);
//Read n bytes of data and put it into the recv_buffer
fread (&rmess, 1, rlen, i2c_port);
//Wait for completion
fflush (i2c_port);
//Send out stop
ioctl (i2c_port, IO_IOCTL_I2C_STOP, NULL);
return 1;
}
thank you!