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.

[参考译文] 编译器/TM4C123GH6PM:在此电路板和 MCP23017 I/O 端口扩展器之间使用 I2C 时遇到问题

Guru**** 2456290 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/641935/compiler-tm4c123gh6pm-having-trouble-using-i2c-between-this-board-and-an-mcp23017-i-o-port-expander

器件型号:TM4C123GH6PM

工具/软件:TI C/C++编译器

大家好、

我目前正在进行一个小型游戏、该游戏需要很多 LED 才能正常工作、因此我决定尝试使用端口扩展器来执行该项目。 遗憾的是、我没有 I2C 方面的经验、因此我不知道我的当前代码为什么不起作用。

我的当前代码:

#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"

#define SLAVE_ADDRESS 0x20


void writeByte (int dataByte1、int dataByte2){//向从站发送数据
   I2CMasterDataPut (I2C1_base、dataByte1);

   I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_START);
   while (I2CMasterBusy (I2C1_base))
       {
       }

   I2CMasterDataPut (I2C1_base、dataByte2);

   I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
   while (I2CMasterBusy (I2C1_base))
       {
       }





int main (空)

   SysCtlClockSet (SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHz);
  
   //初始化 I2C 端口/时钟
   SysCtlPeripheralEnable (SYSCTL_Periph_I2C1);
   SysCtlPeripheralReset (SYSCTL_Periph_I2C1);


   SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);
   GPIOPinConfigure (GPIO_PA6_I2C1SCL);
   GPIOPinConfigure (GPIO_PA7_I2C1SDA);
   GPIOPinTypeI2CSCL (GPIO_Porta_base、GPIO_PIN_6);
   GPIOPinTypeI2C (GPIO_Porta_base、GPIO_PIN_7);


   I2CMasterInitExpClk (I2C1_base、SysCtlClockGet ()、false);


   I2CMasterSlaveAddrSet (I2C1_base、slave_address、false);

   //要发送的数据
   writeByte (0x00、0x00);
   writeByte (0x12、0xFF);


返回0;

从器件地址应该正确、并且所有函数都在正确编译、但我可以使用扩展器实现任何操作。 有什么想法吗?

扩展器数据表: cdn-shop.adafruit.com/.../mcp23017.pdf

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

    很抱歉、这在假期中出现了裂缝!

    首先、您是否已经检查过是否使用了适当的上拉电阻器?

    此外、查看器件数据表、MCP 部件上似乎有一条复位线。 您是否在处理它? 如果未正确处理该部件、则可以将其保持在复位状态。

    代码明智我没有发现任何令人惊讶的错误、尽管我想知道您期望的结果是什么? 没有回读、那么您如何知道扩展器没有发生任何情况?