我最近在跟着论坛学习driver lib的库函数调用,在读取iic的时候,不知道如何来使用这些封装好的函数,这是我改的官方的,大家帮忙看看哈,不知道怎么了,目前没搞定,
#include "driverlib.h"
#define SLAVE_ADDRESS 0x80
uint8_t transmitData0;
uint8_t transmitData1;
uint8_t receivedData;
void main(void)
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);
//Assign I2C pins to USCI_B0
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P3,
GPIO_PIN0 + GPIO_PIN1
);
//Initialize transmit data packet
transmitData0 = 0x81;
transmitData0 = 0xE0;
//Initialize Master
USCI_B_I2C_initMasterParam param = {0};
param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = UCS_getSMCLK();
param.dataRate = USCI_B_I2C_SET_DATA_RATE_100KBPS;
USCI_B_I2C_initMaster(USCI_B0_BASE, ¶m);
//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B0_BASE,
SLAVE_ADDRESS
);
//Set in transmit mode
USCI_B_I2C_setMode(USCI_B0_BASE,
USCI_B_I2C_TRANSMIT_MODE
);
//Enable I2C Module to start operations
USCI_B_I2C_enable(USCI_B0_BASE);
USCI_B_I2C_clearInterrupt(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_INTERRUPT
);
USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
USCI_B_I2C_RECEIVE_INTERRUPT
);
//Send single byte data.
USCI_B_I2C_masterSendSingleByte(USCI_B0_BASE,
transmitData0
);
//Delay until transmission completes
while(USCI_B_I2C_isBusBusy(USCI_B0_BASE))
{
;
}
USCI_B_I2C_masterSendSingleByte(USCI_B0_BASE,
transmitData1
);
//Delay until transmission completes
while(USCI_B_I2C_isBusBusy(USCI_B0_BASE))
{
;
}
USCI_B_I2C_masterReceiveSingleStart(USCI_B0_BASE);
receivedData = USCI_B_I2C_masterReceiveSingle(
USCI_B0_BASE);
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_B0_VECTOR)))
#endif
void USCI_B0_ISR(void)
{
}
|