打印

LM3S6965使用IIC读RTC出现问题了

[复制链接]
3091|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zzz2012|  楼主 | 2012-5-22 09:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
先上代码:

int PCF8563Read(unsigned char address,unsigned char *pbuf,int number)
{
        int i;
        //
        // Specify slave address  
        // 0xA3  --> read
        // 0xA2  --> write
        //
        I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x51, false);
        //
        // Place the character to be sent in the data register
        //
        I2CMasterDataPut(I2C_MASTER_BASE,address);
        //
        // Initiate send of character from Master to Slave
        //
        I2CMasterControl(I2C_MASTER_BASE,  I2C_MASTER_CMD_BURST_SEND_START);
        //
        // Delay until transmission completes
        //
        while(I2CMasterBusy(I2C_MASTER_BASE));
        //指定从机地址
        I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x51, true);
        //Initiate send character from Slave to Master
        // 读取数据命令
        I2CMasterControl(I2C_MASTER_BASE,  I2C_MASTER_CMD_BURST_RECEIVE_START);
       
        //
        // Delay until transmission completes
        //
        for(i = 0; i < number-1; i++)
        {
                while(I2CMasterBusy(I2C_MASTER_BASE));
                *pbuf++ = (unsigned char)I2CMasterDataGet(I2C_MASTER_BASE);
                I2CMasterControl(I2C_MASTER_BASE,  I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        }
        //发送一个停止位
        while(I2CMasterBusy(I2C_MASTER_BASE));
        *pbuf++ = (unsigned char)I2CMasterDataGet(I2C_MASTER_BASE);
        I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
        while(I2CMasterBusBusy(I2C_MASTER_BASE));         return i;
}

使用IIC外挂一个RTC:PCF8563T,程序运行了好几天,发现出现CPU停在最后的一个while循环(红色标志的语句)等待,请问这是什么问题引起的,硬件问题还是软件问题?

相关帖子

沙发
ty新气象| | 2012-5-22 09:47 | 只看该作者
没用过LM3S6965,等看结果。

使用特权

评论回复
板凳
zzz2012|  楼主 | 2012-5-22 10:02 | 只看该作者
补充一下:
IIC只挂一个设备,就PCF8563T。

使用特权

评论回复
地板
zzz2012|  楼主 | 2012-5-23 08:31 | 只看该作者
问题还没有解决,顶起来。

使用特权

评论回复
5
永远的不知| | 2012-5-23 10:10 | 只看该作者
6# zzz2012
#define   BSP_I2C_MODULE
#include <bsp.h>


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/

#define  LM3SXXXX_BASE_I2C0                    0x40020000uL
#define  LM3SXXXX_BASE_I2C1                    0x40021000uL

/*
*********************************************************************************************************
*                                        REGISTER BIT DEFINES
*********************************************************************************************************
*/
/*********************************************************************
                           总线地址分配
*********************************************************************/
#define PCF8563ADDR     0x51        //PCF8563器件地址,默认为1010001x

/*********************************************************************
                         PCF8563寄存器定义
*********************************************************************/
#define PCF8563CTRL0    0x00        //PCF8563控制状态寄存器0
#define PCF8563CTRL1    0x01        //PCF8563控制状态寄存器1
#define PCF8563SECOND   0x02        //PCF8563秒(欠压)寄存器
#define PCF8563MINUTE   0x03        //PCF8563分钟寄存器
#define PCF8563HOUR     0x04        //PCF8563小时寄存器
#define PCF8563DAY      0x05        //PCF8563日寄存器
#define PCF8563WEEK     0x06        //PCF8563星期寄存器
#define PCF8563MONTH    0x07        //PCF8563月(世纪)寄存器
#define PCF8563YEAR     0x08        //PCF8563年寄存器



/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


void PCF8563Write(unsigned char addr,unsigned char data)
{

// Specify slave address  指定从机地址

I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, PCF8563ADDR, false);


// Place the character to be sent in the data register

// 发送子地址

I2CMasterDataPut(I2C1_MASTER_BASE, addr);


// Initiate send of character from Master to Slave

// 设置主机状态

I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);


// Delay until transmission completes

while(I2CMasterBusy(I2C1_MASTER_BASE));


// Place the character to be sent in the data register

I2CMasterDataPut(I2C1_MASTER_BASE, data);


// Initiate send of character from Master to Slave

// 发送数据命令

I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);


// Delay until transmission completes

while(I2CMasterBusy(I2C1_MASTER_BASE));


//  发送结束命令

I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);


//  等待命令发送结束

while(I2CMasterBusy(I2C1_MASTER_BASE));
}

unsigned long PCF8563Read(unsigned char address)
{

unsigned long data;


// Specify slave address  指定从机地址

I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, PCF8563ADDR, false);



// Place the character to be sent in the data register

I2CMasterDataPut(I2C1_MASTER_BASE,address);


// Initiate send of character from Master to Slave

I2CMasterControl(I2C1_MASTER_BASE,  I2C_MASTER_CMD_BURST_SEND_START);



// Delay until transmission completes

while(I2CMasterBusy(I2C1_MASTER_BASE));



//指定从机地址

I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, PCF8563ADDR, true);


//Initiate send character from Slave to Master

// 读取数据命令

I2CMasterControl(I2C1_MASTER_BASE,  I2C_MASTER_CMD_SINGLE_RECEIVE);


// Delay until transmission completes

while(I2CMasterBusy(I2C1_MASTER_BASE));


//get the data

data=I2CMasterDataGet(I2C1_MASTER_BASE);


//发送一个停止位

//I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);


//while(I2CMasterBusBusy(I2C1_MASTER_BASE));



//UARTprintf("read value: %d\n", data);

return data;
}

void BSP_RTCInit(void)
{

unsigned long ulVal;

    // Enable the peripherals used by this example.

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);//开启I2C1模块
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//开启GPIOA模块(PA6+PA7)



// 管脚功能及参数配置  

GPIOPinConfigure(GPIO_PA6_I2C1SCL);//配置PA6复选功能为I2C1SCL

GPIOPinConfigure(GPIO_PA7_I2C1SDA);//配置PA7复选功能为I2C1SDA

GPIOPinTypeI2C(GPIO_PORTA_BASE,

GPIO_PIN_6 | GPIO_PIN_7);//针对PA6、PA7配置管脚电气参数


// Initialize Master and Slave

ulVal = SysCtlClockGet();

I2CMasterInitExpClk(I2C1_MASTER_BASE, ulVal, false);

//I2CMasterEnable(I2C1_MASTER_BASE);
}

void BSP_GetTime(DT * time)
{

time->Second = PCF8563Read(PCF8563SECOND) & 0x7F;

time->Minute = PCF8563Read(PCF8563MINUTE) & 0x7F;

time->Hour = PCF8563Read(PCF8563HOUR) & 0x3F;

time->Day = PCF8563Read(PCF8563DAY) & 0x3F;

time->Week = PCF8563Read(PCF8563WEEK) & 0x07;

time->Month = PCF8563Read(PCF8563MONTH) & 0x1F;

time->Year = PCF8563Read(PCF8563YEAR);
}

void BSP_InitTime(void)
{

PCF8563Write(PCF8563MINUTE, 0x18);

PCF8563Write(PCF8563HOUR, 0x08);

PCF8563Write(PCF8563DAY, 0x05);

PCF8563Write(PCF8563WEEK, 0x06);

PCF8563Write(PCF8563MONTH, 0x11);

PCF8563Write(PCF8563YEAR, 0x11);
}

使用特权

评论回复
6
永远的不知| | 2012-5-23 10:11 | 只看该作者
6# zzz2012
楼上是我8563的代码,您可以参考下。

使用特权

评论回复
7
shenmu2012| | 2012-5-24 10:18 | 只看该作者
很强大的各位啊,不管是用哪个,第一要先保证I2C总线可以用的啊,不然通讯都不同的,两边的路再好也是过不了河啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

19

帖子

0

粉丝