This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/TM4C1294NCPDT:使用 Launchpad 通过 I2C 连接微控制器。

Guru**** 1794070 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/572460/ccs-tm4c1294ncpdt-connecting-the-microcontroller-using-a-launchpad-through-i2c

器件型号:TM4C1294NCPDT

工具/软件:Code Composer Studio

 似乎无法将任何数据输出到阵列。 我不确定是不正确使用数据输出命令还是错误使用阵列。 在调试模式下、launchpad 会自动更改从器件地址的寄存器值、因此我假设磁力计已正确连接到 launchpad。

我已附上我的代码

/*
 * Mag 地址:0x1E (写入:0x3C 读取:0x3D)
 *


//包括
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/i2c.h"
#include "sensorlib/i2cm_drv.h"

//定义语句
#define   Mag_Read_address 0x3D   //将激光雷达从地址定义为0x62
#define   Mag_WRITE_ADDRESS 0x3C
#define NUM_OF_I2CBYTES 255   //定义要读取的 I2C 字节的最大数量
#define Mag_address 0x1E



//函数原型
void ConfigureI2C (void);


//全局变量声明
uint32_t ui32SysClkFreq;   //32位 int、用于存储时钟频率值
uint16_t ui16alldata[2];   //16位数据、用于6个字节的要读取的数据



void ConfigureI2C (void){

   //设置 I2C 外设 I2C7
   SysCtlPeripheralEnable (SYSCTL_Periph_I2C7);
   SysCtlPeripheralEnable (SYSCTL_Periph_GPIOD);
   //while (!SysCtlPeripheralReady (SYSCTL_Periph_GPIOB))   //等待外设为编程做好准备
   //将 PD 配置为 I2C7SCL
   //


   GPIOPinConfigure (GPIO_PD0_I2C7SCL);
   GPIOPinTypeI2CSCL (GPIO_PORTD_BASE、GPIO_PIN_0);
   //将 PB3配置为 I2C7指定 SDA
   GPIOPinConfigure (GPIO_PD1_I2C7SDA);
   GPIOPinTypeI2C (GPIO_PORTD_base、GPIO_PIN_1);

   //使用时钟频率将 uC 配置为 I2C7上的主设备,(false - 100kHz),(true - 400kHz)
   I2CMasterInitExpClk (I2C4_base、ui32SysClkFreq、true);
   返回;
   }



int main (void){

   //将系统时钟设置为120MHz 并存储在变量中
   ui32SysClkFreq = SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz|SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480)、120000000);

   ConfigureI2C();
   //等待外设为编程做好准备
   //
   while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C7));

   while (1){
      int i;
         //设置从器件 I2C 端口、从器件地址、 true - read、false - write
         I2CMasterSlaveAddrSet (I2C7 _BASE、Mag_address、false);
         //将所需的寄存器写入到从器件中
         I2CMasterDataPut (I2C4_base、0x3C);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_START);
         I2CMasterDataPut (I2C4_base、0x00);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C7_BASE、0x70);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x3C);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x01);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0xA0);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x3C);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x02);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x00);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         SysCtlDelay (200);
         I2CMasterDataPut (I2C4_base、0x3D);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_CONT);
         I2CMasterDataPut (I2C4_base、0x06);
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
         //设置从器件 I2C 端口、从器件地址、 true - read、false - write
         I2CMasterSlaveAddrSet (I2C7 _BASE、Mag_address、TRUE);
         //从先前指定的寄存器中读取所需的数据并将其存储在变量中
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_Receive_start);
         ui16alldata[0]= I2CMasterDataGet (I2C4_base);
         for (i=0;i<2;i++)
         {
            I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_Receive_CONT);
            ui16alldata[i+1]= I2CMasterDataGet (I2C4_base);
         }
         I2CMasterControl (I2C4_base、I2C_MASTER_CMD_BURST_Receive_finish);
         ui16alldata[2]= I2CMasterDataGet (I2C7 _BASE);

         SysCtlDelay (2000000);
   }


感谢你的任何帮助。