/*
* main.c
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "driverlib/i2c.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/ssi.h"
#include "lcddriver/uc1701.h"
* main.c
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "driverlib/i2c.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/ssi.h"
#include "lcddriver/uc1701.h"
#define TMP_I2C_ADDR 0b1001000
#define TMP_TEMP_REG 0x01
#define TMP_PIN_I2C_PORT I2C1_BASE
#define TMP_TEMP_REG 0x01
#define TMP_PIN_I2C_PORT I2C1_BASE
uint16_t TMP100DataRead(void);
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
//
GPIOPinTypeGPIOOutputOD(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7);
GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7);
UC1701Init(60000);
UC1701Clear();
UC1701CharDispaly(0, 0, "the temp is:");
UC1701DisplayN(1,0,TMP100DataRead());
SysCtlDelay(1000000);
while(1)
{
{
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
//
GPIOPinTypeGPIOOutputOD(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7);
GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7);
UC1701Init(60000);
UC1701Clear();
UC1701CharDispaly(0, 0, "the temp is:");
UC1701DisplayN(1,0,TMP100DataRead());
SysCtlDelay(1000000);
while(1)
{
}
}
}
/读这部分是/实验指导书上的程序
uint16_t TMP100DataRead(void)
{
uint8_t i2cWriteBuffer;
uint32_t i2cReadBuffer[2];
uint16_t temp_value;
// send to tmp100:
i2cWriteBuffer = TMP_TEMP_REG;
i2cWriteBuffer &= 0x03; // 2 bit valid
// frame 1:
I2CMasterSlaveAddrSet(TMP_PIN_I2C_PORT, TMP_I2C_ADDR, false);
// frame 2:
I2CMasterDataPut(TMP_PIN_I2C_PORT, i2cWriteBuffer);
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_SINGLE_SEND);
// wait finish
while(I2CMasterBusBusy(TMP_PIN_I2C_PORT))
;
// read from tmp100:
// frame 3:
I2CMasterSlaveAddrSet(TMP_PIN_I2C_PORT, TMP_I2C_ADDR, true);
//I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_SINGLE_RECEIVE);
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_START);
// get temperature int value
// frame 4:
i2cReadBuffer[0] = I2CMasterDataGet(TMP_PIN_I2C_PORT);
int a = 500;
while (a--)
;
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
// get the decimal value
// frame 5:
i2cReadBuffer[1] = I2CMasterDataGet(TMP_PIN_I2C_PORT);
// while(I2CMasterBusBusy(TMP_PIN_I2C_PORT))
// ;
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
temp_value = i2cReadBuffer[0] | (i2cReadBuffer[1] << 8);
return temp_value;
}
uint16_t TMP100DataRead(void)
{
uint8_t i2cWriteBuffer;
uint32_t i2cReadBuffer[2];
uint16_t temp_value;
// send to tmp100:
i2cWriteBuffer = TMP_TEMP_REG;
i2cWriteBuffer &= 0x03; // 2 bit valid
// frame 1:
I2CMasterSlaveAddrSet(TMP_PIN_I2C_PORT, TMP_I2C_ADDR, false);
// frame 2:
I2CMasterDataPut(TMP_PIN_I2C_PORT, i2cWriteBuffer);
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_SINGLE_SEND);
// wait finish
while(I2CMasterBusBusy(TMP_PIN_I2C_PORT))
;
// read from tmp100:
// frame 3:
I2CMasterSlaveAddrSet(TMP_PIN_I2C_PORT, TMP_I2C_ADDR, true);
//I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_SINGLE_RECEIVE);
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_START);
// get temperature int value
// frame 4:
i2cReadBuffer[0] = I2CMasterDataGet(TMP_PIN_I2C_PORT);
int a = 500;
while (a--)
;
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
// get the decimal value
// frame 5:
i2cReadBuffer[1] = I2CMasterDataGet(TMP_PIN_I2C_PORT);
// while(I2CMasterBusBusy(TMP_PIN_I2C_PORT))
// ;
I2CMasterControl(TMP_PIN_I2C_PORT, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
temp_value = i2cReadBuffer[0] | (i2cReadBuffer[1] << 8);
return temp_value;
}