I2C changes from 3.2 to 3.4

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C changes from 3.2 to 3.4

Jump to solution
1,232 Views
mikeu
Contributor I

I have a project originally written with MQX version 3.2 that communicates to an I2C real time clock.

This worked as expected.

I have since upgraded to MQX 3.4 and that code no longer runs it just "hangs".

 

Should the I2C code be backwards compatible or do I need to re write for version 3.4?

 

As an example here is a short section that just set the RTC in 3.2

 

    /* Open the I2C controller */        
    rtc_file = fopen("i2c0:", (pointer)(I2C_DEVICE_MASTER_MODE));

 

 

    /* this is later on to set the clock */

    i2c_send_buffer[0] = I2C_RTC_ADDR<<1 | I2C_WRITE_OP;
    i2c_send_buffer[1] = I2C_RTC_CONTROL_STATUS_REGISTER1_ADDR & 0xff;
    i2c_send_buffer[2] = control1;    
    i2c_send_buffer[3] = control2;    
    i2c_send_buffer[4] = seconds_bcd; 
    i2c_send_buffer[5] = minutes_bcd; 
    i2c_send_buffer[6] = hours_bcd; 
    i2c_send_buffer[7] = days_bcd; 
    i2c_send_buffer[8] = weekdays_bcd;
    i2c_send_buffer[9] = months_bcd; 
    i2c_send_buffer[10] = years_bcd;
    i2c_send_buffer[11] = minute_alarm; 
    i2c_send_buffer[12] = hour_alarm;
    i2c_send_buffer[13] = day_alarm;
    i2c_send_buffer[14] = weekday_alarm;
    i2c_send_buffer[15] = clkout;
    i2c_send_buffer[16] = timer;

    /* Write to the RTC */
    result = write(rtc_file, i2c_send_buffer, 17);

 

 

Thanks in advance for your help.

 

Mike

 

0 Kudos
Reply
1 Solution
425 Views
PetrM
Senior Contributor I

Hello,

 

the driver has been refactored to have as universal API as possible.

At least, following sequence is needed now for correct behaviour:

 

i2c_fd=open("i2c0:", NULL);   // master mode is default

param=0x66;                      // addressed device

ioctl(i2c_fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param);

 

fwrite(i2c_send_buffer, 1, 17, i2c_fd);

fflush(i2c_fd); 

ioctl(i2c_fd, IO_IOCTL_I2C_STOP, NULL);

 

Please see I2C example application for more details.

 

Regards,

PetrM

 

View solution in original post

0 Kudos
Reply
1 Reply
426 Views
PetrM
Senior Contributor I

Hello,

 

the driver has been refactored to have as universal API as possible.

At least, following sequence is needed now for correct behaviour:

 

i2c_fd=open("i2c0:", NULL);   // master mode is default

param=0x66;                      // addressed device

ioctl(i2c_fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param);

 

fwrite(i2c_send_buffer, 1, 17, i2c_fd);

fflush(i2c_fd); 

ioctl(i2c_fd, IO_IOCTL_I2C_STOP, NULL);

 

Please see I2C example application for more details.

 

Regards,

PetrM

 

0 Kudos
Reply