简体   繁体   English

示例代码,作为7段LCD驱动器的MCP23017(16引脚IO扩展器,I2C)上的文档

[英]example code, documents on MCP23017 (16 pin IO extender, I2C) as an 7-segment LCD driver

the MCP23017 from Microchip is an I2C based 16-pin IO extender. Microchip的MCP23017是基于I2C的16引脚IO扩展器。 I have been able to set up the device once (set pin direction and values), but after that i cannot change the values as expected unless i reset / power cycle the device. 我已经能够设置一次该设备(设置引脚方向和值),但是在那之后,除非重置/重启设备,否则我无法按预期更改值。 this is the code i used to initalize it and set the pins up the first time: 这是我用来初始化并第一次设置引脚的代码:

I2C_Start();
  I2C_Write(0x40);   // slave address
  I2C_Write(0x00);  // address register
  ... (sequential mode so next 10 are set to I2C_Write(0x00);
  I2C_Write(0x08);  // IOCON: HAEN=1
  I2C_Write(0x08);  // IOCON: HAEN=1
  ... (sequential mode so next 6 are set to I2C_Write(0x00);
  I2C_Write(0xFEu);  // GPIOA
  I2C_Write(0x01u);  // GPIOB
  I2C_Stop();

after this i would like to be able to toggle the output values (0xFE <-> 0x01). 之后,我希望能够切换输出值(0xFE <-> 0x01)。 I attempted this code: 我尝试了这段代码:

I2C_Start();
  I2C_Write(0x40);   // slave address
  I2C_Write(0x12);   // address register
  I2C_Write(0x01u);  // GPIOA
  I2C_Write(0xFEu);  // GPIOB
  I2C_Stop();

at this point it seems to go out to lunch, the pins seem to be random in value (input vs. output, output High vs Low). 此时似乎要吃午饭了,引脚的值似乎是随机的(输入与输出,输出高与低)。 If anyone as used this I2C IO extender please help me out. 如果有人使用过此I2C IO扩展器,请帮助我。 even if your not fully sure your more than welcome to comment. 即使您不能完全确定您也欢迎发表评论。 NOTE: I2C API shown here is a bit bang algorithm all clock cycles have aprox. 注意:此处显示的I2C API是位冲击算法,所有时钟周期都带有aprox。 1ms weights between them. 它们之间的权重为1ms。

useful documents (kind of): http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf 有用的文件(种类): http : //ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf

尝试使用示波器或逻辑分析仪查看SCL和SDA信号,以检查时序和数据,以确保向I / O扩展器发送了您认为的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM