Hi!
I would like to operate motor using cc2650STK, drv8830, DC 6V 55RPM TS-32Gz370-69.
using IAR Embedded Workbench IDE
but it didn`t operate at all....
i using Api sensorTag adding drv8830.c and drv8830.h of applying the function to be called
I2C that the connection between mcu and motor driver I`m not sure.
How can I verify that the I2C communication between two modules? The settings that are in the source code
If it is how to fix
I will source attached.
#include "sensor_drv8830.h" #include "sensor.h" #include "bsp_i2c.h" #define SENSOR_I2C_ADDRESS DRV8830ADDR_NN // fault status #define DRV8830_F_CLEAR 0x80 #define SENSOR_SELECT() bspI2cSelect(BSP_I2C_INTERFACE_0,DRV8830ADDR_NN) #define SENSOR_DESELECT() bspI2cDeselect() #define DRV8830ADDR_00 0xc0 #define DRV8830ADDR_0N 0xc2 #define DRV8830ADDR_01 0xc4 #define DRV8830ADDR_N0 0xc6 #define DRV8830ADDR_NN 0xc8 //write address jp2, jp3 is open #define DRV8830ADDR_N1 0xca #define DRV8830ADDR_10 0xcc #define DRV8830ADDR_1N 0xce #define DRV8830ADDR_11 0xd0 // fault status #define DRV8830_F_ILIMIT 0x10 #define DRV8830_F_OTS 0x08 #define DRV8830_F_UVLO 0x04 #define DRV8830_F_OCP 0x02 #define DRV8830_F_FAULT 0x01 // motor status #define DRV8830_FREE 0x00 #define DRV8830_CW 0x01 #define DRV8830_CCW 0x02 #define DRV8830_BREAK 0x03 // register address #define DRV8830_CONTROL 0x00 #define DRV8830_FAULT 0x01 // voltage data #define DRV8830_V_R48 0x06 #define DRV8830_V_R56 0x07 #define DRV8830_V_R64 0x08 #define DRV8830_V_R72 0x09 // (no definition from 0.82V to 4.74V) #define DRV8830_V_4R82 0x3c #define DRV8830_V_4R90 0x3d #define DRV8830_V_4R98 0x3e #define DRV8830_V_5R06 0x3f #define DRV8830_V_MIN 0x06 #define DRV8830_V_MAX 0x3f #define DRV8830_V_RANGE (DRV8830_V_MAX - DRV8830_V_MIN) // Voltage Control #define DRV8830_FREE 0x00 #define DRV8830_POSI 0x01 #define DRV8830_NEGA 0x02 #define DRV8830_BREAK 0x03 // Voltage table #define TBL_OFFSET 0x06 #define TBL_SIZE 58 #define TBL_MAX_VALUE (5.06f) #define TBL_MIN_VALUE (0.48f) #define DATA_SIZE 2 /* Register length */ #define REGISTER_LENGTH 2 static uint8_t buf[DATA_SIZE]; static uint16_t val; //static bool success; const float voltage_table [] = { 0.48, 0.56, 0.64, 0.72, 0.80, 0.88, 0.96, 1.04, 1.12, 1.20, 1.29, 1.37, 1.45, 1.53, 1.61, 1.69, 1.77, 1.85, 1.93, 2.01, 2.09, 2.17, 2.25, 2.33, 2.41, 2.49, 2.57, 2.65, 2.73, 2.81, 2.89, 2.97, 3.05, 3.13, 3.21, 3.29, 3.37, 3.45, 3.53, 3.61, 3.69, 3.77, 3.86, 3.94, 4.02, 4.10, 4.18, 4.26, 4.34, 4.42, 4.50, 4.58, 4.66, 4.74, 4.82, 4.90, 4.98, 5.06 }; bool sensorDrv8830Init(void){ return sensorDrv8830Enable(true); } bool sensorDrv8830Enable(bool enable){ bool success; uint8_t pwm_rate = 0; if (!SENSOR_SELECT()) return false; buf[0]=0x00; success = sensorReadReg(DRV8830_FAULT, &buf[0], REGISTER_LENGTH); val = DRV8830_F_CLEAR; success = sensorWriteReg(DRV8830_FAULT, (uint8_t *)&val, REGISTER_LENGTH); if(enable) val = DRV8830_CW; else val = DRV8830_FREE; success = sensorWriteReg(DRV8830_CONTROL, (uint8_t *)&val, REGISTER_LENGTH); pwm_rate = DRV8830_V_MAX; val = (pwm_rate << 2) + DRV8830_CW; success = sensorWriteReg(DRV8830_CONTROL, (uint8_t *)&val, REGISTER_LENGTH); SensorTag_blinkLed(Board_LED1,10); SENSOR_DESELECT(); return success; } void sensorDrv8830Start(void) { } void sensorDrv8830Speed(float speed) { uint8_t direction = 0; uint8_t pwm_rate = 0; uint8_t dt[2]; bool success; if (speed == 0.0f ){ pwm_rate = DRV8830_V_MIN; direction = DRV8830_FREE; } else if (speed > 0.0f){ pwm_rate = (uint8_t)(DRV8830_V_RANGE * speed) + DRV8830_V_MIN; direction = DRV8830_CW; } else if (speed < 0.0f){ speed *= -1; pwm_rate = (uint8_t)(DRV8830_V_RANGE * speed) + DRV8830_V_MIN; direction = DRV8830_CCW; } if (pwm_rate > DRV8830_V_MAX){ pwm_rate = DRV8830_V_MAX; } else if (pwm_rate < DRV8830_V_MIN){ pwm_rate = DRV8830_V_MIN; } dt[0] = DRV8830_CONTROL; dt[1] = (pwm_rate << 2) + direction; // success = sensorReadReg(DRV8830_CONTROL, (uint8_t *)&val,sizeof(val)); // if (success) // { // if (!SENSOR_SELECT()) // return; SENSOR_SELECT(); bspI2cWrite((uint8_t *)dt, 2); SENSOR_DESELECT(); //} } void sensorDrv8830Voltage(float volt) { uint8_t direction = 0; uint8_t pwm_rate = 0; uint8_t dt[2]; bool success; success = sensorReadReg(DRV8830_CONTROL, (uint8_t *)&val,sizeof(val)); if (volt < 0){ direction = DRV8830_NEGA; volt *= -1; } else { direction = DRV8830_POSI; } if (volt >= TBL_MAX_VALUE) { pwm_rate = TBL_SIZE + TBL_OFFSET - 1; } else { for (uint32_t i = 0; i < TBL_SIZE; i++){ if (volt < voltage_table[i]) { //printf("n=%d, voltage_table[i]=%f\r\n", i, voltage_table[i]); if (i == 0){ pwm_rate = 0; direction = DRV8830_FREE; } else { pwm_rate = i + TBL_OFFSET; } break; } } } //printf("volt=%f, pwm=0x%x, dir=%d\r\n", volt, pwm_rate, direction); dt[0] = DRV8830_CONTROL; dt[1] = (pwm_rate << 2) + direction; if (success) { if (!SENSOR_SELECT()) return; success = bspI2cWrite((uint8_t *)dt, 2); SENSOR_DESELECT(); } } uint8_t sensorDrv8830Status() { uint8_t dt[2]; bool success; dt[0] = DRV8830_FAULT; success = sensorReadReg(DRV8830_CONTROL, (uint8_t *)&val,sizeof(val)); if (success) { if (!SENSOR_SELECT()) return dt[0]; success = bspI2cWriteRead((uint8_t *)dt, 1, (uint8_t *)dt, 1); SENSOR_DESELECT(); } return dt[0]; } void sensorDrv8830Reset() { uint8_t dt[2]; bool success; dt[0] = DRV8830_FAULT; dt[1] = DRV8830_F_CLEAR; if (success) { if (!SENSOR_SELECT()) return; success = bspI2cWrite((uint8_t *)dt, 2); SENSOR_DESELECT(); } }