在用61IC的I2C 例程来调试TI的Concerto_F28M35xx_control_CARD,读板子上的EEPROM,我手上也有61IC的开发板,因为没有仿真器目前,所以只能调试TI的了。
TI的板子用的是PB6 PB7(当然没有忘记要跳线), 61IC用的是PB2 PB3。
我把例程中相应的改为PB6 PB7,并且,GPIOPINUNLOCK了PB7(虽然不知道是为什么,网上说要这样,实际中不这样的话,程序运动到writedata时,会一直等待isfinish?)。
但是结果始终不对,READDATA始终和WRITEDATA不对。
不知道问题出在哪,没有很多时间从DATASHEET慢慢的找问题。
希望高手能指点。
谢谢。
下面是我的代码:
#include "inc/hw_i2c.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/debug.h"
#define ID_I2C_ADDR 0x50
static tBoolean
WriteData(unsigned char ucAddr, unsigned char ucData);
static tBoolean
ReadData(unsigned char *pucData, unsigned long ulOffset,
unsigned long ulCount);
int main(void)
{
unsigned char pucData[8]={'a','b','c','d','e','f','g','h'};
unsigned char dat[8];
unsigned char i;
unsigned char value1, value2, value3, value4;
// Disable Protection
HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5;
// Setup main clock tree for 75MHz – M3 and 150MHz – C28x
SysCtlClockConfigSet(SYSCTL_SYSDIV_1 | SYSCTL_M3SSDIV_2 | SYSCTL_USE_PLL |
(SYSCTL_SPLLIMULT_M & 0x0F));
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); /* 使能I2C外设 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); /* 使能GPIO外设 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
// Disable clock supply for the watchdog modules
SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG1);
SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG0);
IntMasterEnable(); /* 使能处理器中断 */
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_6);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7);
GPIOPinUnlock(GPIO_PORTB_BASE, GPIO_PIN_7);
//GPIOPinUnlock(GPIO_PORTB_BASE, GPIO_PIN_6);
//GPIOPinConfigure(GPIO_PB2_I2C0SCL);
//GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinConfigure(GPIO_PB7_I2C0SCL);
GPIOPinConfigure(GPIO_PB6_I2C0SDA);
//GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7);
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_6, ~0);
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7, ~0);
I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(
SYSTEM_CLOCK_SPEED), false);
// for(i=0;i<8;i++)
// WriteData(0x08+i,pucData[i]);
ReadData(dat,0x08,8);
value1=dat[0];
value2=dat[1];
value3=dat[2];
value4=dat[3];
for(i=0;i<8;i++)
{
if(dat[i]!=pucData[i])
{
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_6, 0);
while(1);
}
}
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7, 0);
while(1);
}
void Delays (unsigned char no)
{
int i, j;
for ( ; no > 0; no–) {
for (i = 0; i < 150; i++) {
for (j = 0; j < 255; j++);
}
}
}
static tBoolean
WaitI2CFinished(void)
{
//
// Wait until the current byte has been transferred.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
{
}
if(I2CMasterErr(I2C0_MASTER_BASE) != I2C_MASTER_ERR_NONE)
{
I2CMasterIntClear(I2C0_MASTER_BASE);
return(false);
}
//
// Clear any interrupts set.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false))
{
I2CMasterIntClear(I2C0_MASTER_BASE);
}
return(true);
}
static tBoolean ReadData(unsigned char *pucData, unsigned long ulOffset,unsigned long ulCount)
{
unsigned long ulToRead;
I2CMasterIntClear(I2C0_MASTER_BASE);
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, false);
I2CMasterDataPut(I2C0_MASTER_BASE, ulOffset);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
if(!WaitI2CFinished())
return(false);
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, true);
I2CMasterControl(I2C0_MASTER_BASE,
((ulCount > 1) ? I2C_MASTER_CMD_BURST_RECEIVE_START :
I2C_MASTER_CMD_SINGLE_RECEIVE));
ulToRead = ulCount;
while(ulToRead)
{
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0) { }
I2CMasterIntClear(I2C0_MASTER_BASE);
*pucData++ = I2CMasterDataGet(I2C0_MASTER_BASE);
ulToRead–;
if(ulToRead)
I2CMasterControl(I2C0_MASTER_BASE,
((ulToRead == 1) ?
I2C_MASTER_CMD_BURST_RECEIVE_FINISH :
I2C_MASTER_CMD_BURST_RECEIVE_CONT));
}
return(true);
}
static tBoolean WriteData(unsigned char ucAddr, unsigned char ucData)
{
I2CMasterIntClear(I2C0_MASTER_BASE);
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, false);
I2CMasterDataPut(I2C0_MASTER_BASE, ucAddr);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
if(!WaitI2CFinished())
return(false);
I2CMasterDataPut(I2C0_MASTER_BASE, ucData);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
if(!WaitI2CFinished())
return(false);
// SysCtlDelay(SysCtlClockGet()/600 );
Delays(15);
return(true);
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
demo xie:
TI工程师们,请帮忙指点一下啊。程序中的 for(i=0;i<8;i++) WriteData(0x08+i,pucData[i]);
是测试的时候注销掉的,正常时没有注销的。
我用的板子是F28M35xx ISO controlCARD RELEASE 1.0,是不是这个版本的I2C有bug?
板子上的EEPROM是CSI的24C256