TI中文支持网
TI专业的中文技术问题搜集分享网站

关于cc2652r模拟iic的问题

用的传感器是一个陀螺仪,结果接收不到数据。

/* For usleep() */

#include <unistd.h>
#include <stdint.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>

/* Driver configuration */
#include "ti_drivers_config.h"
#include "hw_uart.h"
//#include "hw_i2c.h"
#include "user_i2c.h"
#include "hw_bma250e.h"
#include "hw_bma250e_Spec.h"
#define Slave_Addr 0x18

static uint16_t BMA250E_MakeInt(uint8_t Low, uint16_t High)
{
uint16_t u;

u = (High << 2) | (Low >> 6);

return u;
}

void BMA250E_Init(void)
{
Write_Add(Slave_Addr, 0x0F, 0x03);
Write_Add(Slave_Addr, 0x10, 0x08);

}

void BMA250E_GetData(void)
{
//bool ret = false;
uint8_t buffer[7] = {0,0,0,0,0,0,0};
uint16_t bufXYZ[4] = {0,0,0,0};
buffer[0]=Read_Add(Slave_Addr,BMA250_REG_X_LSB);
buffer[1]=Read_Add(Slave_Addr,BMA250_REG_X_MSB);
buffer[2]=Read_Add(Slave_Addr,BMA250_REG_Y_LSB);
buffer[3]=Read_Add(Slave_Addr,BMA250_REG_Y_MSB);
buffer[4]=Read_Add(Slave_Addr,BMA250_REG_Z_LSB);
buffer[5]=Read_Add(Slave_Addr,BMA250_REG_Z_MSB);
buffer[6]=Read_Add(Slave_Addr,BMA250_REG_TEMP);

bufXYZ[0] = BMA250E_MakeInt(buffer[0], buffer[1]);
bufXYZ[1] = BMA250E_MakeInt(buffer[2], buffer[3]);
bufXYZ[2] = BMA250E_MakeInt(buffer[4], buffer[5]);
bufXYZ[3] = (uint8_t)(buffer[6] / 2) + 24;

HwUARTPrintf("X: %ld\r\nY: %ld\r\nZ: %ld\r\nTemp: %d\r\n",bufXYZ[0],bufXYZ[1],bufXYZ[2],bufXYZ[3]);

}

/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
/* 1 second delay */
uint32_t time = 1;

/* Call driver init functions */
GPIO_init();
// I2C_init();
// SPI_init();
// UART_init();
// Watchdog_init();
HwUARTInit();
IIC_PIN_Init();
BMA250E_Init();
/* Configure the LED pin */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

while (1) {
sleep(time);
GPIO_toggle(CONFIG_GPIO_LED_0);
//BMA250E_IDTest();
//BMA250E_GetData();
BMA250E_GetData();

}
}

user6254143:

这是iic的程序

#include "user_i2c.h"
#include "ti_drivers_config.h"

void IIC_PIN_Init(void)
{GPIO_setConfig(SCL_PIN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);GPIO_setConfig(SDA_PIN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
}

void IIC_Start(void)
{SDA_OUT;SDA_PIN_HIGHT;SCL_PIN_HIGHT;// SDA_PIN_HIGHT;SDA_OUT;SDA_PIN_LOW;SCL_PIN_LOW;
}

void IIC_Stop(void)
{SDA_OUT;SDA_PIN_LOW;SCL_PIN_HIGHT;SDA_OUT;SDA_PIN_HIGHT;SCL_PIN_LOW;
}

void Write_IIC_Byte(unsigned char IIC_Byte)
{unsigned char i;for(i=0;i<8;i++){if(IIC_Byte & 0x80){SDA_OUT;SDA_PIN_HIGHT;}
else{SDA_OUT;SDA_PIN_LOW;}
SCL_PIN_HIGHT;SCL_PIN_LOW;IIC_Byte<<=1;}SDA_OUT;SDA_PIN_HIGHT;SCL_PIN_HIGHT;SCL_PIN_LOW;

}

uint8_t Read_IIC_Byte(void)
{uint8_t rdata=0,i=0;SCL_PIN_LOW;SDA_IN;for(i=0;i<8;i++){SCL_PIN_HIGHT;rdata= (rdata << 1) | SDA_PIN_READ;SCL_PIN_LOW;}return rdata;
}

bool IIC_WaitAck(void)
{SCL_PIN_LOW;SDA_OUT;SDA_PIN_HIGHT;SCL_PIN_HIGHT;
SDA_IN;if(SDA_PIN_READ){SCL_PIN_LOW;return false;}else{SCL_PIN_LOW;return true;}

}

void IIC_NOAck(void)
{SCL_PIN_LOW;SDA_OUT;SDA_PIN_HIGHT;SCL_PIN_HIGHT;SCL_PIN_LOW;

}

void IIC_Ack(void)
{SCL_PIN_LOW;SDA_OUT;SDA_PIN_LOW;SCL_PIN_HIGHT;SCL_PIN_LOW;
}
void Write_Add(uint8_t add,uint8_t comd,uint8_t wdata)
{IIC_Start(); Write_IIC_Byte(add);Write_IIC_Byte(comd);Write_IIC_Byte(wdata);IIC_Stop();
}

uint8_t Read_Add(uint8_t add,uint8_t comd)
{uint8_t tdata;IIC_Start();Write_IIC_Byte(add);Write_IIC_Byte(comd);IIC_Start();Write_IIC_Byte(add+1);tdata = Read_IIC_Byte();IIC_NOAck();IIC_Stop();return tdata;
}

Viki Shi:

回复 user6254143:

是用SCS模拟吗?建议参考该软件help中的I2C部分实现

user6254143:

回复 Viki Shi:

不是的,直接在ccs中写的,因为该传感器的操作函数是用模拟iic实现的,所以我想用gpio模拟iic

Viki Shi:

回复 user6254143:

建议用SCS模拟I2C等外设

赞(0)
未经允许不得转载:TI中文支持网 » 关于cc2652r模拟iic的问题
分享到: 更多 (0)