Team Walter / Mbed OS NonPingPong_PICO_LoRa

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa by Walter Luu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AO19_lib.cpp Source File

AO19_lib.cpp

00001 
00002 #include "mbed.h"
00003 #include "AO19_lib.h"
00004 
00005 // *****************************************************************************
00006 //   AO19_write_register(char, char, char)  writes single byte to AO19
00007 //                       char   I2C address
00008 //                       char   AO19 register address
00009 //                       char   data byte to be writen
00010 //   returns                    0 on success ACK, 1 on NACK 
00011 // *****************************************************************************
00012 
00013 int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char byte){
00014     char data[2];               // char type ranges from 0 to 255 (8 bytes)
00015     int error;
00016     data[0] = reg_add;
00017     data[1] = byte;
00018     error = i2c->write(I2C_add,data,2);  
00019     //if(DEBUG)db.printf("wr[%02X %02X %d]\r\n", data[0], data[1], error);
00020     return error; 
00021     
00022 }
00023 
00024 /// ****************************************************************************
00025 //   AO19_write_register(char, char, char *, int)  writes multiple bytes to AO19
00026 //                       char   I2C address
00027 //                       char   AO19 register address
00028 //                       char * data vector of bytes to be written
00029 //                       int    number of bytes to write
00030 //   returns                    0 on success ACK, 1 on NACK 
00031 // *****************************************************************************
00032 
00033 int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n){
00034     int i;   
00035     //set start address
00036     char data[16];
00037     int error;                          
00038     data[0] = reg_add; 
00039     for(i=1;i<=n;i++){                   
00040        data[i] = bytes[i-1];
00041     }
00042     error = i2c->write(I2C_add,data,n+1);  // send n bytes of data
00043   
00044     return error;      
00045 }
00046 
00047 // *****************************************************************************
00048 //   AO19_read_register(char, char, char *)  reads single byte from AO19
00049 //                       char   I2C address
00050 //                       char   AO19 register address
00051 //                       char * data vector for read bytes to be stored in 
00052 //   returns                    0 on success, 1 on fail 
00053 // *****************************************************************************
00054 
00055 int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes){
00056     int error;
00057     error = i2c->write(I2C_add,&reg_add,1,1); 
00058     if(error)return error;   
00059     error = i2c->read(I2C_add,bytes,1);  
00060     //if(DEBUG)db.printf("rr e[%d]\r\n",error);
00061     return error; 
00062 }
00063 
00064 // *****************************************************************************
00065 //   AO19_read_register(char, char, char *, int)  reads byte(s) from AO19
00066 //                       char   I2C address
00067 //                       char   OT07 register address
00068 //                       char * data vector for read bytes to be stored in 
00069 //                       int    number of bytes to read
00070 //   returns                    0 on success, 1 on fail 
00071 // *****************************************************************************
00072 
00073 int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n){
00074     int error;
00075     error = i2c->write(I2C_add,&reg_add,1,1); 
00076     if(error)return error;   
00077     error = i2c->read(I2C_add,bytes,n);  
00078     //if(DEBUG)db.printf("rr e[%d]\r\n",error);
00079     return error; 
00080 }