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

MSP430FR2433: MSP430的模拟IIC问题

Part Number:MSP430FR2433

为什么我用同样的程序 使用P1.2 P1.3作为模拟IIC的IO口就可以成功模拟,当我把IO口改为P1.0,P1.1后就模拟失败,程序确保已将相关IO口全部替换。

相关原理图已附上

Susan Yang:

https://www.ti.com.cn/cn/lit/ds/symlink/msp430fr2433.pdf 

,

user6518570:

这个我看到了 可是P1.0和P1.1不是能用作普通IO来配置输出吗?

,

Susan Yang:

P1.2 P1.3本身就是I2C的引脚,不需要GPIO模拟。您现在程序是怎样的?

,

user6518570:

我知道的 可是我需要配置模拟IIC,我的P1.2和P1.3已经配置为硬件IIC通信了,我现在需要一个模拟IIC,就是不理解为什么P1.0和P1.1不能用作模拟,上拉电阻也加上了

,

Susan Yang:

模拟I2C的话,您需要自己做I2C的时序等,这和P1.2和P1.3的硬件I2C程序是不同的。您直接在P1.2和P1.3上修改程序是不可以的

,

Susan Yang:

您可以看一下

https://www.ti.com/lit/an/slaa703a/slaa703a.pdf 

,

user6518570:

这么说吧 ,我用P1.2和P1.3做了两套IIC程序,一套模拟IIC,一套硬件IIC,都已经成功实现通信了,然后我将模拟IIC的那套程序的IO口仅仅换为P1.0与P1.1之后就无法通信了

,

user6518570:

这是我模拟IIC软件时序的问题吗? 所以P1.0与P1.1是普通IO是 可以作为模拟IIC的SDA与SCL配置的是吗

,

Susan Yang:

user6518570 说:所以P1.0与P1.1是普通IO是 可以作为模拟IIC的SDA与SCL配置的是吗

Software implementation of the master I 2C requires only two GPIOs and one timer. The two GPIOs are used to emulate SDA and SCL signals. Any ordinary GPIO can be used, and there are no special requirements such as interrupt capability. 

软件实现I2C只需要两个 GPIO 和一个定时器。这两个 GPIO 是用于模拟 SDA 和 SCL 信号。任何普通的GPIO都可以使用,没有特殊的中断能力等要求。

,

user6518570:

我用P1.2和P1.3做了两套IIC程序,一套模拟IIC,一套硬件IIC,都已经成功实现通信了,然后我将模拟IIC的那套程序的IO口仅仅换为P1.0与P1.1之后就无法通信了。这个问题的原因有可能是什么呢,您还没有回答

,

Susan Yang:

user6518570 说:然后我将模拟IIC的那套程序的IO口仅仅换为P1.0与P1.1之后就无法通信了。这个问题的原因有可能是什么呢

若是可以还是提供下程序,不然就只能纯靠猜测

,

user6518570:

#include "include.h"/**********************************************************************函数名称:void Simulative_I2C_Init(void)*函数功能:I2C初始化*入口参数:无*出口参数:无*备注:无
*********************************************************************/
void Simulative_I2C_Init(void)
{P1DIR|= BIT2;P1DIR|= BIT3;PM5CTL0 &= ~LOCKLPM5;SCL_H;SDA_H;}/**********************************************************************函数名称:void I2C_Start(void)*函数功能:I2C起始信号*入口参数:无*出口参数:无*备注:无
*********************************************************************/
void I2C_Start(void)
{SDA_H;SCL_H;delay_us(10);SDA_L;delay_us(10);SCL_L;delay_us(10);}/**********************************************************************函数名称:void I2C_Stop(void)*函数功能:I2C停止信号*入口参数:无*出口参数:无*备注:无
*********************************************************************/
void I2C_Stop(void)
{SDA_OUT;SDA_L;SCL_H;delay_us(10);SDA_H;delay_us(10);SCL_L;
}/**********************************************************************函数名称:void I2C_Ack(void)*函数功能:应答信号(主机发送)*入口参数:无*出口参数:无*备注:无
*********************************************************************/
void I2C_Ack(void)
{SDA_L;delay_us(10);SCL_H;delay_us(10);SCL_L;delay_us(10);}/**********************************************************************函数名称:void I2C_NoAck(void)*函数功能:非应答信号(主机发送)*入口参数:无*出口参数:无*备注:无
*********************************************************************/
void I2C_NoAck(void)
{SDA_H;delay_us(10);SCL_H;delay_us(10);SCL_L;delay_us(10);}/**********************************************************************函数名称:unsigned char Wait_Ack(void)*函数功能:规定时间内检测从机发来的Ack*入口参数:无*出口参数:0-收到,1-未收到*备注:无
*********************************************************************/
unsigned char Wait_Ack(void)
{unsigned char tiemout=0;SDA_H;delay_us(10);SDA_IN;SCL_H;delay_us(10);while(READ_SDA){tiemout++;if(tiemout>250){I2C_Stop();return 1;}}SCL_L;SDA_OUT;return 0;}/**********************************************************************函数名称:unsigned char Send_Byte(unsigned char l_u8Data)*函数功能:发送一字节数据到SDA信号线上*入口参数:要发送的数据( l_u8Data )*出口参数:成功返回0,失败返回1*备注:无
*********************************************************************/
unsigned char Send_Byte(unsigned char l_u8Data)
{unsigned char i;for(i=0; i<8; i++){SCL_L;delay_us(10);if(l_u8Data & 0x80){SDA_H;}else{SDA_L;}delay_us(10);SCL_H;delay_us(10);l_u8Data = l_u8Data << 1;}SCL_L;delay_us(10);if(Wait_Ack()){return 1;}else{return 0;}
}/**********************************************************************函数名称:unsigned char Receive_Byte(void)*函数功能:从SDA信号线上接收一字节数据*入口参数:无*出口参数:接收到的数据( l_u8RecData )*备注:无
*********************************************************************/
unsigned char Receive_Byte(void)
{unsigned char l_u8Count, l_u8RecData=0;SCL_L;delay_us(10);SDA_H;SDA_IN;for(l_u8Count=0; l_u8Count<8; l_u8Count++){SCL_H;delay_us(10);l_u8RecData <<= 1;if(READ_SDA){l_u8RecData |= 0x01;}SCL_L;delay_us(10);}SDA_OUT;return l_u8RecData;
}/**********************************************************************函数名称:unsigned char I2C_WriteByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char l_u8Data)*函数功能:写一字节的数据到设备*入口参数:从机地址(l_u8SlaveAddr),数据写入地址(l_u8Addr),写入的数据(l_u8Data)*出口参数:成功返回0,失败返回1*备注:无
*********************************************************************/
unsigned char I2C_WriteByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char l_u8Data)
{I2C_Start();if(Send_Byte(l_u8SlaveAddr&0xFE)){return 1;}if(Send_Byte(l_u8Addr)){return 1;}if(Send_Byte(l_u8Data)){return 1;}I2C_Stop();return 0;
}/**********************************************************************函数名称:unsigned char I2C_WriteNByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data, unsigned char l_u8Length)*函数功能:写指定大小的数据到设备*入口参数:从机地址(l_u8SlaveAddr),寄存器地址(l_u8Addr),写入的数据指针(l_u8Data),写入的数据大小(l_u8Length)*出口参数:成功返回0,失败返回1*备注:无
*********************************************************************/
unsigned char I2C_WriteNByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data, unsigned char l_u8Length)
{unsigned char i;I2C_Start();if(Send_Byte(l_u8SlaveAddr&0xFE)){return 1;}if(Send_Byte(l_u8Addr)){return 1;}for(i=0; i<l_u8Length; i++){if(Send_Byte(l_u8Data[i])){return 1;}}I2C_Stop();return 0;
}/**********************************************************************函数名称:unsigned char I2C_ReadByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data)*函数功能:读取一字节的数据*入口参数:从机地址(l_u8SlaveAddr),读取的寄存器地址(l_u8Addr),数据存储地址(l_u8Data)*出口参数:成功返回0,失败返回1*备注:无
*********************************************************************/
unsigned char I2C_ReadByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data)
{I2C_Start();if(Send_Byte(l_u8SlaveAddr&0xFE)){return 1;}if(Send_Byte(l_u8Addr)){return 1;}I2C_Start();if(Send_Byte(l_u8SlaveAddr|0x01)){return 1;}*l_u8Data = Receive_Byte();I2C_NoAck();I2C_Stop();return 0;
}/**********************************************************************函数名称:unsigned char I2C_ReadNByte(uint8_t slaveAddr, uint8_t addr, uint8_t* data, uint8_t length)*函数功能:读取指定大小的数据*入口参数:从机地址(l_u8SlaveAddr),读取数据的首地址(l_u8Addr),存放数据指针(l_u8Data),读取的数据大小(l_u8Length)*出口参数:成功返回0,失败返回1*备注:无
*********************************************************************/
unsigned char I2C_ReadNByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data, unsigned char l_u8Length)
{unsigned char i;I2C_Start();if(Send_Byte(l_u8SlaveAddr&0xFE)){return 1;}if(Send_Byte(l_u8Addr)){return 1;}I2C_Start();if(Send_Byte(l_u8SlaveAddr|0x01)){return 1;}for(i=0; i<l_u8Length-1; i++){l_u8Data[i] = Receive_Byte();I2C_Ack();}l_u8Data[i] = Receive_Byte();I2C_NoAck();I2C_Stop();return 0;
}
#ifndef __SIMIIC_H
#define __SIMIIC_H/******************************************IO宏定义******************************************/
#define SDA_IN(P1DIR &= ~ BIT2)
#define SDA_OUT(P1DIR |= BIT2)#define READ_SDAP1IN & BIT2#define SDA_H(P1OUT |= BIT2) //p1.2 SDA
#define SDA_L(P1OUT &= ~BIT2)#define SCL_H(P1OUT |= BIT3) // P1.3 SCL
#define SCL_L(P1OUT &= ~BIT3)/******************************************函数接口声明******************************************/
extern void Simulative_I2C_Init(void);
extern void I2C_Start(void);
extern void I2C_Stop(void);
extern void I2C_Ack(void);
extern void I2C_NoAck(void);
extern unsigned char Wait_Ack(void);
extern unsigned char Send_Byte(unsigned char l_u8Data);
extern unsigned char Receive_Byte(void);
extern unsigned char I2C_WriteByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char l_u8Data);
extern unsigned char I2C_ReadByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data);
extern unsigned char I2C_WriteNByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data, unsigned char l_u8Length);
extern unsigned char I2C_ReadNByte(unsigned char l_u8SlaveAddr, unsigned char l_u8Addr, unsigned char* l_u8Data, unsigned char l_u8Length);
#endif

,

user6518570:

改为P1.0,P1.1后就模拟失败了

,

Susan Yang:

我会在确认后给您回复

,

Susan Yang:

请您参考下面的回复

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1029217/msp430fr2433-software-i2c/3804798#3804798

您可以补充一下您的问题。

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