TIVA C系列问题,I2C接口 [英] TIva C Series problems with I2C Interface

查看:259
本文介绍了TIVA C系列问题,I2C接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图接口我全凭静脉麻醉C系列与Sparkfun分线板,IMU数字组合板 - 自由ITG3200 / ADXL345的6度,我具有I2C接口的麻烦。

I'm currently trying to interface my Tiva C Series with a Sparkfun Breakout Board, IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345 and I'm having trouble with the I2C interface.

目前,这是我的code:

currently this is my code:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"

uint8_t SLAVE_ADDRESS = 0x68;

uint32_t first_byte, second_byte, temperature, result;

void i2c_setup(void) {


//Enable the I2C Module
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

//Wait at least 5 clock cycles
SysCtlDelay(2);

//Configure SDA and SCL
GPIOPinConfigure(GPIO_PE4_I2C2SCL);

GPIOPinConfigure(GPIO_PE5_I2C2SDA);

//Wait at least 5 clock cycles
SysCtlDelay(2);

//Set PE4 as SCL
GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4);

//Set PE5 as SDA
GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5);

//Configure Master,
I2CMasterInitExpClk(I2C2_BASE, SysCtlClockGet(), false);

}

uint32_t i2c_read() {

I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C2_BASE, 0x1A);

I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_SEND);

while(I2CMasterBusBusy(I2C2_BASE)); //Loop until the bus is no longer busy

I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, true );

I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

while(I2CMasterBusBusy(I2C2_BASE)); //Loop until the bus is no longer busy

first_byte = I2CMasterDataGet(I2C2_BASE);

return first_byte;

}

void setup()
{
Serial.begin(9600);
i2c_setup();
}

void loop()
{

int test = i2c_read();
Serial.println(test);
delay(1000);
}

我使用的能源公司来测试我的程序,当我尝试从指定的寄存器读取数据时,我得到了相同的结果,无论哪个注册我选择,结果总是十进制229​​(这是加速度计的设备地址)。

I'm using Energia to test my program, and when I try to read from the specified register, I get the same result, no matter which register I choose, the result is always decimal 229 (this is the Accelerometer's Device Address).

有人能指出我在正确的方向,我一直在找我的code相当长的一段时间,还是不知道什么是错...

Can somebody point me in the right direction, I've been looking at my code for quite some time and still don't know whats wrong...

谢谢!

推荐答案

我通过你的code脱脂,一切似乎好了。显然,事情是工作的权利,如果你得到回应。但就像马丁说,没有身临其境有些困难搞清楚的问题。而不是写0x1A的,你可以尝试使用了accelerametor其他I2C命令之一?此外,如果跳线连接到VDD您的地址应该是0×69(105十进制)你确定这是为0x68?

I skimmed through your code and everything seems Okay. Clearly something is working right if you get a response. But Like Martin said , figuring the problem without being there is somewhat difficult. Instead of Writing 0x1A can you try using one of the other I2C commands for the accelerametor ? Also if the jumper is connected to VDD your address should be 0x69 (105 decimal) are you sure it's 0x68 ?

我抬头对sparkfuns网站上的文档和他们提供的以下列表
命令。

I looked up the documentation on sparkfuns website and they provided the following list of commands.

 char WHO_AM_I = 0x00;
 char SMPLRT_DIV= 0x15;
 char DLPF_FS = 0x16;
 char GYRO_XOUT_H = 0x1D;
 char GYRO_XOUT_L = 0x1E;
 char GYRO_YOUT_H = 0x1F;
 char GYRO_YOUT_L = 0x20;
 char GYRO_ZOUT_H = 0x21;
 char GYRO_ZOUT_L = 0x22;

GL希望一切顺利。本来要我自己买的玩弄所以请给我!

GL hope everything works out. Been meaning to buy my own to play around with so keep me posted !

这篇关于TIVA C系列问题,I2C接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆