Browse Source

Begin porting modules to unified i2c procedures.

Vladimir N. Shilov 3 years ago
parent
commit
a6686ef43d
1 changed files with 17 additions and 0 deletions
  1. 17 0
      Src/ds3231.c

+ 17 - 0
Src/ds3231.c

@@ -2,15 +2,27 @@
 
 #define RTC_TX_BUF_SIZE 4
 
+extern int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
+extern int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
+
 static uint8_t i2cBufTX[RTC_TX_BUF_SIZE] = {0};
 
 /**
  * @brief Инициализация RTC
  */
 void RTC_Init(void) {
+  uint8_t buf[3] = {0};
   /* Clear flags */
   Flag.I2C_TX_End = 0;
 
+  buf[0] = DS3231_1HZ; // set 1 Hz output squware
+  buf[1] = 0x0; // disable 32 kHz output
+
+  user_i2c_write(DS3231_I2C_ADDR, DS3231_ADDR_CONTROL, buf, 2);
+}
+
+void test_w(rtc_t * data) {
+
   /* Source: Address of the I2C TX buffer. */
   DMA1_Channel3->CMAR = (uint32_t)&i2cBufTX;
   /* Destination: I2C TX data register. */
@@ -45,6 +57,11 @@ void RTC_ReadAll(rtc_t * data) {
   Flag.I2C_RX_End = 0;
   Flag.I2C_TX_End = 0;
 
+  user_i2c_read(DS3231_I2C_ADDR, DS3231_ADDR_TIME, (uint8_t *)data, DS3231_SIZE_ALL);
+}
+
+void test_r(rtc_t * data) {
+
   /* Source: Address of the I2C RX buffer. */
   DMA1_Channel2->CMAR = (uint32_t)data;
   /* Destination: I2C RX data register. */