主题中讨论的其他器件:SysConfig
工具与软件:
大家好、我在使用 DS1307。 我不断从 I2C 线路收到无意义的时间。 我将保留下面编写的代码。 您能帮我解决可能出错的问题吗?
#include "ti_msp_dl_config.h"
#include "LCD_Func.h"
int val=0;
#define DS1307_ADDRESS 0x68
#define 秒0x00
#define minutes 0x01
#define Hours 0x02
#define Day 0x03
#define Date 0x04
#define Month 0x05
#define 年份0x06
/* I2C 目标地址*/
/*从 DS1307接收到的数据*/
易失性 uint8_t gRxPacket[7];
uint8_t 秒;// Saniyeler
uint8_t minutes ;// Dakikalar
uint8_t 小时;// Saatler
uint8_t dayOfWeek ;/ Haftanın günü
uint8_t dayOfMonth ;/ Ayın günü
uint8_t 月;//天
uint8_t 年;
int bcdToDec (int val){
返回((val / 16)* 10 + val % 16);
}
uint8_t rxData;
uint8_t readDS1307Register (uint8_t regAddr)
{
DL_I2C_fillControllerTXFIFO (I2C_INST、®Addr、1);
while (! (DL_I2C_getControllerStatus (I2C_INST)和 DL_I2C_CONTROLLER_STATUS_IDLE);
DL_I2C_startControllerTransfer (I2C_INST、DS1307_ADDRESS、
DL_I2C_CONTROLLER_DIRECTION_RX、1);
while (DL_I2C_isControllerRXFIFOEMpty (I2C_INST))
;
rxData = DL_I2C_receiveControllerData (I2C_INST);
if (DL_I2C_getControllerStatus (I2C_INST)和 DL_I2C_CONTROLLER_STATUS_ERROR){
__BKPT (0);// hata durumunda duraklat
}
返回 bcdToDec (rxData);
}
int main (void)
{
SYSCFG_DL_init ();
uint8_t start_address = 0x00;
while (1){
// DS13710den saniyeleri Oku ve yazdır
// DS13710den saniyeleri Oku ve yazdır
uint8_t seconds = readDS1307Register (秒);
printf ("秒:%02d\n"、秒);
// DS13730den dakikaları Oku ve yazdır
uint8_t minutes = readDS1307Register (minutes);
printf ("minut:%02d\n"、分钟);
// DS13710den saatleri Oku ve yazdır
uint8_t hours = readDS1307Register (hours);
printf ("小时数:%02d\n"、小时数);
// DS13730den günü Oku ve yazdır
uint8_t day = readDS1307Register (day);
printf ("天:%02d\n"、天);
// DS13710den tarihi Oku ve yazdır
uint8_t date = readDS1307Register (Date);
printf ("日期:%02d\n"、日期);
// DS13730den ayı Oku ve yazdır
uint8_t month = readDS1307Register (month);
printf ("monty:%02d\n"、月);
// DS13730den yılı Oku ve yazdır
uint8_t year = readDS1307Register (Year);
printf ("年:%02d\n"、年);
printf ("//////////////////////////////////////////////////////////////////////////////////////////// \n");
delay_cycles (160000000);
// toggle_gpio_pin ();
}
}