FYI: Basic I2C Lib

Author
_edx_
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2016/09/21 11:56:28
  • Location: 0
  • Status: online
2018/12/05 17:36:09 (permalink)
0

FYI: Basic I2C Lib

Hi there,
As the title suggest (maybe not), here is a very basic harmony compatible i2c library, if i find the time, maybe i'll improve them, but for now at least do the important, read and write, so how it works:
 
1.- Configure harmony to use I2C, here're the details (image:i2c_forum.png):
 
 
 
2.- Add the prototypes to the .h or .c file
 
void i2c_write(I2C_MODULE_ID index, uint8_t i2c_dir, uint8_t *i2cbuffer, size_t size);
void i2c_read(I2C_MODULE_ID index, uint8_t i2c_dir, uint8_t *dir, size_t size_dir, size_t num_datos, uint8_t *rxBuff);
 
3.- Use them :-)
 
Here's an example, i'm going to read the Who_am_I register of a MMA8452Q accelerometer
 
#define ACCEL_ADDR 0x1D
#define I2C_NUM_DATOS 0X10
void main(){
static uint8_t datos[I2C_NUM_DATOS];
uint8_t reg_dir[] = {0x0D};
i2c_read(I2C_ID_2,ACCEL_ADDR,reg_dir,sizeof(reg_dir),1,datos);
}

 
The output gives the value (0x2A) of the register, that was exactly what we were waiting for (image:i2c.png):
 
 
 
I have tested the lib on PIC32MX564F128H, PIC32MX274F256B and PIC32MX270F256B, so in theory any PIC32MX can use it, indeed (with some luck) the PIC32MZ could use them, wait till weekend and i could be able to confirm it.
 
Any doubt or if you find any error, please do not hesitate to let me know, that's all for now, and last but not least
do not forget to visit http://www.edx-twin3.org for updates and things related to pics :1

Attached Image(s)

#1

2 Replies Related Threads

    Nikolay_Po
    Super Member
    • Total Posts : 1740
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: offline
    Re: FYI: Basic I2C Lib 2018/12/06 00:59:11 (permalink)
    0
    Is this "closed source" project?
    #2
    _edx_
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2016/09/21 11:56:28
    • Location: 0
    • Status: online
    Re: FYI: Basic I2C Lib 2018/12/06 09:05:14 (permalink)
    0
    Hi there,
     
    First of all, thanks for you time, for now it'll be closed, but i always tend to release the source once it works flawless, i did it with Byteman (https://certification.oshwa.org/mx000001.html), so just let me work a little while with the code and i'll release it.

    Regards :1
    Nikolay_Po
    Is this "closed source" project?




    #3
    Jump to:
    © 2018 APG vNext Commercial Version 4.5