由于要写TM1680, 写命令跟写数据, 所以需要使用CC2541的I2C, 2541是有硬件I2C的.
tm1680.c:
#include "tm1680.h"
//TM1680是先发送配置, 然后发送数据.
void masterConfig(void);
void masterSendData(void);
void sendTest(void){
//uint8 buffer[24]={0x0f,0x0e};
//HalI2CWrite(2, buffer);
//HalI2CRead(2,buffer);
masterConfig();
masterSendData();
}
void masterConfig(void){
uint8 configArray[]={SYSDIS,COM16NMOS,RCMODE1,SYSEN,LEDON};
HalI2CWrite(5, configArray);
}
//只有一个值得说的点, TM1680要先发送起始的页地址, 然后发送32位的数据.
void masterSendData(void){
uint8 dataArray[33];
int i=0;
dataArray[0]=0x00;
for(i=1;i<33;i++){
dataArray[i]=0xFF;
}
HalI2CWrite(33, dataArray);
}
void HalTM1680Init(uint8 dev_addr )
{
HalI2CInit(dev_addr, i2cClock_533KHZ);
}
tm1680.h定义了一些命令的别名:
#ifndef HAL_TM1680_H
#define HAL_TM1680_H
#include "hal_i2c.h"
#include "hal_types.h"
#define SYSDIS 0x80
#define SYSEN 0x81
#define LEDOFF 0x82
#define LEDON 0x83
#define BLINKOFF 0x88
#define BLINK2HZ 0x89
#define BLINK1HZ 0x8A
#define BLINK0_5HZ 0x8B
#define SLAVEMODE 0x90
#define RCMODE0 0x98
#define RCMODE1 0x9A
#define EXTCLK0 0x9C
#define EXTCLK1 0x9E
#define COM8NMOS 0xA0
#define COM16NMOS 0xA4
#define COM8PMOS 0xA8
#define COM16PMOS 0xAC
void HalTM1680Init(uint8 dev_addr);
void sendTest(void);
#endif
唯一的问题是硬件I2C两个byte中间等待了很久, 不知道为啥, 回头试试模拟的I2C吧.