Showing posts with label BLE Stack. Show all posts
Showing posts with label BLE Stack. Show all posts

Friday, October 22, 2021

Add write capability to Characteristics 5 in TI CC26xx BLE simple_peripheral example

The following steps show you how to add write capability to Characteristics 5 in TI CC26xx BLE simple_peripheral example. In simple_gatt_profile.c

1. Revise "static uint8 simpleProfileChar5Props = GATT_PROP_READ;" to "static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE;"

2. Revise the following code in simpleProfileAttrTbl

      // Characteristic Value 5
      {
        { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
        GATT_PERMIT_AUTHEN_READ,
        0,
        simpleProfileChar5
      },

to

      // Characteristic Value 5
      {
        { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
        GATT_PERMIT_AUTHEN_READ | GATT_PERMIT_WRITE,
        0,
        simpleProfileChar5
      },

3. Add the following code into simpleProfile_WriteAttrCB

      case SIMPLEPROFILE_CHAR5_UUID:

      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len > SIMPLEPROFILE_CHAR5_LEN )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        memcpy(pCurValue,pValue,len);
        if( pAttr->pValue == &simpleProfileChar5 )
        {
          notifyApp = SIMPLEPROFILE_CHAR5;
        }
      }

      break;

Build the project and you can use TI SimpleLink Starter App or LightBlue App to test Characteristics 5 with write capability.

Tuesday, September 1, 2020

How to remove OAD feature on CC26x2/CC13x2 project_zero

 The following steps show you how to remove OAD feature on CC26x2/CC13x2 project_zero

 1. Replace C:\ti\simplelink_cc13x2_26x2_sdk_4_10_03_02_eng\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\project_zero\tirtos\ccs\cc13x2_cc26x2_app.cmd
   with C:\ti\simplelink_cc13x2_26x2_sdk_4_10_03_02_eng\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\tirtos\ccs\cc13x2_cc26x2_app.cmd
   
2. Check "Exclude from build" on project_zero OAD folder in CCS Project Explorer.

3. Remove all OAD_xxx related code from projec_zero.c and _imgHdr

4. Change project_zero_app.cfg

m3Hwi.nvicCCR.UNALIGN_TRP = 0;
//m3Hwi.nvicCCR.UNALIGN_TRP = 1;

/* Put reset vector after OAD metadata */
var compilerOpts = prog.build.target.ccOpts.prefix; // Get the target compiler options
var regex = /(?:\-\-define\=)(\w*)(?:\=*\w*\s)/g;
var compilerDefs = [];
while ((tmp = regex.exec(compilerOpts)) !== null) compilerDefs.push(tmp[1]); // Parse compiler symbols

if (compilerDefs.indexOf('SECURITY') > -1) { // Check for SECURITY compiler symbol
    m3Hwi.resetVectorAddress = 0x90; // Image B Reset Vector Address
}
else {
    m3Hwi.resetVectorAddress = 0x50; // Image A Reset Vector Address
}

/* Put interrupt vector at start of RAM so interrupts can be configured at runtime */
m3Hwi.vectorTableAddress  = 0x20000000;

To

m3Hwi.nvicCCR.UNALIGN_TRP = 0;
//m3Hwi.nvicCCR.UNALIGN_TRP = 1;

/* Put reset vector at start of Flash */
m3Hwi.resetVectorAddress  = 0x0;

/* Put interrupt vector at start of RAM so interrupts can be configured at runtime */
m3Hwi.vectorTableAddress  = 0x20000000;

Thursday, June 4, 2020

How to add you own custom board files to CC26xx BLE stack


The following steps show you how to add you own custom board files to CC26xx BLE stack using CC2650 BLE stack 2.2.04.06 version

1. Create CC2650_YK folder under C:\ti\simplelink\ble_sdk_2_02_04_06\src\boards\

2.
   2.1 Copy Board.h/CC2650_LAUNCHXL.h/CC2650_LAUNCHXL.c from C:\ti\simplelink\ble_sdk_2_02_04_06\src\boards\CC2650_LAUNCHXL to C:\ti\simplelink\ble_sdk_2_02_04_06\src\boards\CC2650_YK
  
   2.2 Rename CC2650_LAUNCHXL.h/CC2650_LAUNCHXL.c to CC2650_YK.h/CC2650_YK.c
  
   2.3 Revise #include "CC2650_LAUNCHXL.h" in Board.h to #include "CC2650_YK.h"

3. Create cc2650yk folder under C:\ti\simplelink\ble_sdk_2_02_04_06\src\target

4
   4.1 Copy cc2650lp_board.h/cc2650lp_board.c from C:\ti\simplelink\ble_sdk_2_02_04_06\src\target\cc2650lp to C:\ti\simplelink\ble_sdk_2_02_04_06\src\target\cc2650yk

   4.2 Rename cc2650lp_board.h/cc2650lp_board.c to cc2650yk_board.h/cc2650yk_board.c

   4.3 Add the following codes in cc2650yk_board.h
      
       #elif defined(CC2650_YK)
       #include <../../boards/CC2650_YK/Board.h>

   4.4 Add the following codes in cc2650yk_board.c

       #elif defined(CC2650_YK)
       #include <../../boards/CC2650_YK/Board.h>
       #include <../../boards/CC2650_YK/CC2650_YK.c>

5.
   5.1 Add the following codes in board.h
  
       #elif defined(CC2650_YK)
       #include "./cc2650yk/cc2650yk_board.h"

   5.2 Add the following codes in board.c
  
       #elif defined(CC2650_YK)
       #include "./cc2650yk/cc2650yk_board.c"

6. Change CC2650_LAUNCHXL in Predefined Symbols to CC2650_YK

7. Now you can build the code with your own custom board.

Monday, May 18, 2020

SwitchBot DIY using LPSTK-CC1352R , SG90 servo motor, and ProjectZero to away from COVID-19.

Due to COVID-19, people don't want to touch anything such as light switch arbitrarily and it is any super easy to DIY light switch robot to allow you to turn on or off light through BLE of you SmartPhone instead of touching the switch directly.

The follow steps show you how to DIY SwitchBot using Texas Instruments LPSTK-CC1352R, SG90 servo motor, and ProjectZero.

1. Add CONFIG_PWM_0 and use DIO22 as PWM output pin in project_zero.syscfg



2. Add "#include < ti/drivers/PWM.h >" and the following global variables in project_zero.c to use PWM related APIs later.

/* Period and duty in microseconds */
int16_t   pwmPeriod = 20000;
int16_t   duty = 1500;
int16_t   dutyInc = 500;

int16_t i=0;

/* Sleep time in microseconds */
PWM_Handle pwm1 = NULL;
PWM_Params params;

3. Add the following PZ_SERVO_EVT, servoClock, and Servo_clockHandler to send PZ_SERVO_EVT.

#define PZ_SERVO_EVT         11
static Clock_Struct servoClock;static void Servo_clockHandler(UArg arg);

static void Servo_clockHandler(UArg arg)
{
    //PWM_setDuty(pwm1, duty);
    pzButtonState_t *pButtonState = ICall_malloc(sizeof(pzButtonState_t));
            if(pButtonState != NULL)
            {
                //*pButtonState = buttonMsg;
                if(ProjectZero_enqueueMsg(PZ_SERVO_EVT, pButtonState) != SUCCESS)
                {
                  ICall_free(pButtonState);
                }
            }
}

4. Add "case PZ_SERVO_EVT:" in ProjectZero_processApplicationMessage to put SG90 back to original position after writing ON/OFF characteristics

      case PZ_SERVO_EVT:
      {
          PWM_setDuty(pwm1, duty);
          break;
      }


5.  Init/start servoClock and PWM in ProjectZero_init.

    Util_constructClock(&servoClock, Servo_clockHandler, 300, 0, false, 0);
    Util_startClock(&servoClock);

    PWM_init();
    PWM_Params_init(&params);
    params.dutyUnits = PWM_DUTY_US;
    params.dutyValue = 0;
    params.periodUnits = PWM_PERIOD_US;
    params.periodValue = pwmPeriod;
    pwm1 = PWM_open(CONFIG_PWM_0, &params);
    if (pwm1 == NULL) {
        /* CONFIG_PWM_0 did not open */
        while (1);
    }

    PWM_start(pwm1);
    PWM_setDuty(pwm1, duty);

6. In "case LS_LED0_ID:..." section of ProjectZero_LedService_ValueChangeHandler. Add the following code to set PWM to rotate SG90 servo motor according to ON/OFF characteristics writing.

        if (pCharData->data[0]!=0){
            PWM_setDuty(pwm1, duty-500);
            Util_startClock(&servoClock);
        }
        else{
            PWM_setDuty(pwm1, duty+800);
            Util_startClock(&servoClock);
        }


7. Build and download firmware into LPSTK-CC1352R

8. Connect GND/3V3/DIO22 pins on LPSTK-CC1352R to BROWN(GND)/RED(PWR)/ORANGE(PWM) on SG90.

9. Power on LPSTK-CC1352R and use TI SimpleLink Starter App to connect to Project Zero to toggle ON/OFF.






Tuesday, December 17, 2019

How to create a periodic event to toggle BLE Advertising in CC26xx simple_peripheral example

The following steps show you how to create a periodic event to toggle BLE Advertising every 10 seconds in CC26xx simple_peripheral example.

In simple_peripheral.c, add the following codes:

1. Add "#define ADV_PERIODIC_EVT Event_Id_01" for new periodic event.

2. Add "#define ADV_PERIODIC_EVT_PERIOD 10000" to define the period as 10 seconds.

3. Add ADV_PERIODIC_EVT to Bitwise OR of all events to pend on.

    #define SBP_ALL_EVENTS       (SBP_ICALL_EVT        | \
                                                         SBP_QUEUE_EVT        | \
                                                         ADV_PERIODIC_EVT     | \
                                                         SBP_PERIODIC_EVT)

4. Add "advertEnabledPeriod = TRUE;" as a global variable for toggling BLE advertising.

5. Add "static Clock_Struct periodicClockAdv;" for periodic clock.

6. In SimplePeripheral_init(), add the following lines to start periodic event for toggling BLE advertising.

    Util_constructClock(&periodicClockAdv, SimplePeripheral_clockHandler,
                      ADV_PERIODIC_EVT_PERIOD, 0, false, ADV_PERIODIC_EVT);
    Util_startClock(&periodicClockAdv);



7.  Add the following codes in SimplePeripheral_taskFxn() to toggle BLE advertising in ADV_PERIODIC_EVT event which is triggered every 10 seconds.

      if (events & ADV_PERIODIC_EVT)
      {
        Util_startClock(&periodicClockAdv);
        if(advertEnabledPeriod==TRUE){
            advertEnabledPeriod=FALSE;
        } else {
            advertEnabledPeriod=TRUE;
        }
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                                 &advertEnabledPeriod);

      }


8. After building and download hex into your CC26xx device, you can use SimpleLink Starter APP to scan and check if BLE advertising is toggled every 10 seconds.

Monday, December 16, 2019

How to use indication in simple_peripheral example and use Btool to enable indication.

The following steps show you how to revise CC26xx simple_peripheral example to use indication in simple_peripheral example and use Btool to enable indication.

1. Import CC26xx simple_peripheral example into CCS.

2. Replace "static ICall_EntityID selfEntity;" with "ICall_EntityID selfEntity;" in simple_peripheral.c.

3. Revise the following lines in simple_gatt_profile.c.

    3.a Add "extern ICall_EntityID selfEntity;" in EXTERNAL VARIABLES section.

    3.b Change "static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;" to "static uint8 simpleProfileChar4Props = GATT_PROP_INDICATE;".
   
    3.c Change "status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,  offset, GATT_CLIENT_CFG_NOTIFY);" to "status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,  offset, GATT_CLIENT_CFG_INDICATE );".

    3.d Change

          GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &simpleProfileChar4, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    INVALID_TASK_ID, simpleProfile_ReadAttrCB );
        
          to

          GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &simpleProfileChar4, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    selfEntity, simpleProfile_ReadAttrCB );

4. Build simple_peripheral project and download hex to your LaunchPad. Check what BLE MAC address is on Teraterm (or any other terminal tools).



5. Start Btool to do BLE scan and select matched BLE MAC address to establish connection.



6. Write indication enable (02 00 in hex) into Characteristic Value Handle 0x0028 to enable indication and you can receive characteristic 4 indication on Btool.




Wednesday, September 18, 2019

How to read TX power from CC2640R2 BLE Stack

The following steps show you how to read TX power from CC2640R2 BLE Stack. I use simple_central example for testing.

1. Call "HCI_ReadTransmitPowerLevelCmd(0, HCI_READ_CURRENT_TX_POWER_LEVEL);" in the end of SimpleCentral_init().

2. In SimpleCentral_processCmdCompleteEvt, add the following red codes to receive current TX power.

static void SimpleCentral_processCmdCompleteEvt(hciEvt_CmdComplete_t *pMsg)
{
  switch (pMsg->cmdOpcode)
  {
    case HCI_READ_TRANSMIT_POWER:
    {
        int8 get_tx_pwr = (int8)pMsg->pReturnParam[3];

        Display_print1(dispHandle, SC_ROW_SEPARATOR, 0, "TX power is %d db",get_tx_pwr);
        break;
    }

    case HCI_READ_RSSI:
    {
#ifndef Display_DISABLE_ALL
      uint16_t connHandle = BUILD_UINT16(pMsg->pReturnParam[1],
                                         pMsg->pReturnParam[2]);
      int8 rssi = (int8)pMsg->pReturnParam[3];
     
      Display_printf(dispHandle, SC_ROW_ANY_CONN, 0, "%s: RSSI %d dBm",
                   SimpleCentral_getConnAddrStr(connHandle), rssi);

#endif
      break;
    }

    default:
      break;
  }
}

Wednesday, January 3, 2018

How to create a new task in TI RTOS to use ICall service like osal_snv_write and osal_snv_read.

The following steps show you how to create a new task in TI RTOS to use ICall service like osal_snv_write and osal_snv_read. I will use ProjectZero in TI BLE Stack 2.2.1 as an example running on LAUNCHXL-CC2650 to do it.

1. Increase OSAL_MAX_NUM_PROXY_TASKS in BLE Stack project osal.c and rebuild Stack project to download it to your LAUNCHXL-CC2650.

2. Increase ICALL_MAX_NUM_TASKS and ICALL_MAX_NUM_ENTITIES in ProjectZero application Predefined Symbols.

3. Add the following Test_createTask function in ProjectZero.c and claim function prototype "extern void Test_createTask(void);" in ProjectZero.h

// Task configuration
#define TEST_TASK_STACK_SIZE                   800
Task_Struct testTask;
Char testTaskStack[TEST_TASK_STACK_SIZE ];

void Test_createTask(void)
{
  Task_Params taskParams;

  // Configure task
  Task_Params_init(&taskParams);
  taskParams.stack = testTaskStack;
  taskParams.stackSize = TEST_TASK_STACK_SIZE ;
  taskParams.priority = 2;

  Task_construct(&testTask, TestFunction, &taskParams, NULL);
}

4. Add the following TestFunction function in ProjectZero.c

// Entity ID globally used to check for source and/or destination of messages
static ICall_EntityID testEntity;
// Semaphore globally used to post events to the application thread
static ICall_Semaphore testsem;

uint8 status_snv;
uint8 write_buffer[10];
uint8 read_buffer[10];

static void TestFunction(UArg a0, UArg a1)
{

  ICall_registerApp(&testEntity, &testsem);
  while(1)
  {
      write_buffer[0] = 0x12;
      write_buffer[1] = 0x12;
      write_buffer[2] = 0x12;
      write_buffer[3] = 0x12;

      status_snv = osal_snv_write(0x80,10, (uint8_t *)write_buffer );

      //Do ADC Polling and Data processing
      read_buffer[0] = 0x0;
      read_buffer[1] = 0x0;
      read_buffer[2] = 0x0;
      read_buffer[3] = 0x0;

      status_snv = osal_snv_read(0x80,10, (uint8_t *)read_buffer );
  }


5. Call "Test_createTask();" right after "ProjectZero_createTask();" to create TestFunction task to use ICall service for osal_snv_write/osal_snv_read.

Thursday, October 27, 2016

How to create a periodic event for CC253x/CC254x Z-Stack and BLE Stack.

The following codes show example to create a periodic event that is triggered every 5 seconds for CC253x in Z-Stack and you can do it accordingly for CC254x in BLE Stack.

1. Add "#define PERIODIC_EVT 0x0001"in your code. Please note that event define has to be an unused bit mask of uint16.

2. Put  the following line at where you want to start PERIODIC_EVT

osal_start_timerEx( zcl_XXX_TaskID, PERIODIC_EVT, 10 );


2. Create PERIODIC_EVT processing in zcl_XXX_event_loop
if( events & PERIODIC_EVT )
{
  //Do things that need periodic processing here!
  ...
  osal_start_timerEx( zcl_XXX_TaskID, PERIODIC_EVT, 5000 );
  return (events ^ PERIODIC_EVT);
}

Friday, June 24, 2016

How to use TI BLE Stack HostTest to send advertising

How to use TI BLE Stack HostTest to send advertising using Btool in Adv. Commands tab:

1. GAP_DeviceInit, set profileRole to Peripheral and hit Send Command
2. GAP_UpdateAdvertisingData, set adType toGAPADVERT_ADVERTISEMENT_DATA and hit Send Command.
3. GAP_MakeDiscoverable and hit Send Command to start advertising.
4. GAP_EndDiscoverable and hit Send Command to stop advertising.

Friday, April 1, 2016

Steps for TI CC26xx BLE stack applications to use System_printf

1) Modify your appBLE.cfg config file (e.g. CCS->Project Explorer->YourApp->TOOLS->appBLE.cfg)

//System.SupportProxy = SysCallback; //Comment out this line and add the following 3 lines
var SysStd = xdc.useModule("xdc.runtime.SysStd");
var System = xdc.useModule("xdc.runtime.System");
System.SupportProxy = SysStd;

2) Add the following header file to your C file

#include < xdc/runtime/System.h >

3. Use System_printf("Test\n") and System_flush() to output messages.

Wednesday, October 28, 2015

How to use SensorTag CC2650STK with CC-DEVPACK-DEBUGGER as HostTest and connect to BLE BTool.

The following steps show you how to use SensorTag CC2650STK with CC-DEVPACK-DEBUGGER as HostTest and connect to BLE BTool.

1. Revise the following code in Board.h

#define Board_UART_RX IOID_2 /* RF1.7 */
#define Board_UART_TX IOID_3 /* RF1.9 */

to

#define Board_UART_RX IOID_28 /* RF1.7 */
#define Board_UART_TX IOID_29 /* RF1.9 */

2. Rebuild HostTest and download it to CC2650STK.
3. Disconnect CC2650STK from CC-DEVPACK-DEBUGGER and connect it to restart.
4. Find COM port of XDS110 Class Application/User UART.



5. Open BTool and select COM port of XDS110 Class Application/User UART. Remember to select Flow to None.




6. You should see CC2650STK BLE HostTest is connected.



Wednesday, August 26, 2015

How to create a periodic event in TI Z-Stack or BLE-Stack

The following codes are example to start PERIODIC_EVT every second and you can do any periodic processing in PERIODIC_EVT.

//Put where you want to start PERIODIC_EVT
osal_start_timerEx( XXX_TaskID, SENSOR_READ_EVT, 1000 );

//For Z-Stack, create PERIODIC_EVT processing in zcl_XXX_event_loop
//For BLE-Stack, create PERIODIC_EVT processing in xxx_ProcessEvent
  if( events & PERIODIC_EVT )
  {
    //Do things that need periodic processing here!
    ...
    osal_start_timerEx( XXX_TaskID, PERIODIC_EVT, 1000 );
    return (events ^ PERIODIC_EVT);
  }

Wednesday, November 26, 2014

How to output PWM from CC2530/CC2541

Refer to CC253x/4x User's Guide. The following sample code can send PWM to P1_4.


  PERCFG &= (~(0x20)); // Select Timer 3 Alternative 1 location
  P2SEL |=0x20;
  P2DIR |= 0xC0;  // Give priority to Timer 1 channel2-3
  P1SEL |= BV(4);  // Set P1_4 to peripheral, Timer 1,channel 2
  P1DIR |= BV(4);

  T3CTL &= ~0x10;             // Stop timer 3 (if it was running)
  T3CTL |= 0x04;              // Clear timer 3
  T3CTL &= ~0x08;             // Disable Timer 3 overflow interrupts
  T3CTL |= 0x03;              // Timer 3 mode = 3 - Up/Down

  T3CCTL1 &= ~0x40;           // Disable channel 0 interrupts
  T3CCTL1 |= 0x04;            // Ch0 mode = compare
  T3CCTL1 |= 0x10;            // Ch0 output compare mode = toggle on compare

  T3CTL &= ~0xE0;   // Clear Prescaler divider value
  T3CTL |= 0xA0;    //Set Prescaler divider value = Tick frequency /32
  T3CC0 = 128;      //Set ticks = 128

  // Start timer
  T3CTL |= 0x10;

Then, the following example shows you how you output 6.5K PWM with 50% duty cycle to P1.1 with CC2530 Timer 1.

  PERCFG |= BV(6); // Select Timer 1 Alternative 2 location
  P2DIR = (P2DIR & ~0xC0) | 0x80; // Give priority to Timer 1
  P1SEL |= BV(1);  // Set P1_1 to peripheral

  T1CC0L = 0x3A;   // PWM signal period
  T1CC0H = 0x01;

  T1CC1L = 0x9D;  // PWM duty cycle
  T1CC1H = 0x00;

  T1CCTL1 = 0x1c;

  T1CTL |= (BV(2)|0x03); // divide with 128 and to do i up-down mode

Wednesday, December 4, 2013

CC2530/CC2541 ADC Howto in TI Z-Stack/BLE Stack

It is always a mystery to beginner to use ADC on CC2530/CC2541. Here, I post how to use TI Z-Stack/BLE Stack API to read ADC value on CC2530/CC2541. I hope this post can help anyone who struggles on CC2530/CC2541 ADC usage. In the followings, I show how to use P0_2 as ADC input, HAL_ADC_REF_125V as reference voltage, and HAL_ADC_RESOLUTION_10, HAL_ADC_RESOLUTION_12, HAL_ADC_RESOLUTION_14 as ADC resolution respectively.

1.  Read ADC value from P0_2 using HAL_ADC_REF_125V as reference voltage and HAL_ADC_RESOLUTION_10 as ADC resolution.

        uint16 adc_ain2=0;
        HalAdcSetReference(HAL_ADC_REF_125V);
        adc_ain2=HalAdcRead(HAL_ADC_CHN_AIN2,HAL_ADC_RESOLUTION_10);



The max measurable voltage of P0_2 is 1.15 because I am using HAL_ADC_REF_125V as reference voltage here. If the input voltage is larger than 1.15V, the ADC reading adc_ain2 will be always 511. If I connect P0_2 to 0.5V, I will have ADC reading adc_ain2=223. Then, we can convert the reading 223 to measured voltage using the following equation.
measured voltage = 1.15x223/511=0.501...

2. If I change  HAL_ADC_RESOLUTION_12 (the max reading is 2047) as ADC resolution and connect P0_2 to 0.5V, I will have ADC reading adc_ain2=886. Then, we can convert the reading 889 to measured voltage using the following equation.
measured voltage = 1.15x889/2047=0.499...


3. If I change  HAL_ADC_RESOLUTION_14 (the max reading is 8191) as ADC resolution and connect P0_2 to 0.5V, I will have ADC reading adc_ain2=3550. Then, we can convert the reading 3550 to measured voltage using the following equation.
measured voltage = 1.15x3550/8191=0.498...