Skip to content

Commit

Permalink
Add RAM read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Salamon committed Sep 15, 2019
1 parent 7152b40 commit 54fa7b2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Inc/DS1307.h
@@ -1,12 +1,13 @@
/*
* DS1307.h
*
* The MIT License.
* Created on: 4.09.2019
* Author: Mateusz Salamon
* Contact: mateusz@msalamon.pl
*
* Website:
* GitHub:
* Website: https://msalamon.pl/dalsze-zmagania-z-rtc-ds1307-i-pcf8563-na-stm32/
* GitHub: https://github.com/lamik/DS1307_RTC_STM32_HAL
*/

//
Expand Down Expand Up @@ -61,6 +62,9 @@ void DS1307_SQWRateSelect(uint8_t Rate);
void DS1307_OutputControl(uint8_t Enable);
void DS1307_ClockHalt(uint8_t Enable);

void DS1307_ReadRAM(uint8_t Address, uint8_t *Value, uint8_t Length);
void DS1307_WriteRAM(uint8_t Address, uint8_t *Value, uint8_t Length);

void DS1307_SetDateTime(RTCDateTime *DateTime);
#ifdef DS1307_USE_DMA
void DS1307_ReceiveDateTimeDMA(void); // Use in DS1307 Interrupt handler
Expand Down
7 changes: 6 additions & 1 deletion README.md
@@ -1,9 +1,14 @@
DS1307 RTC with STM32 HAL.

STM43F410RB

STM32CubeIDE 1.0.2

HAL F4 1.24.1

Description:

Description: https://msalamon.pl/dalsze-zmagania-z-rtc-ds1307-i-pcf8563-na-stm32/

GitHub: https://github.com/lamik/DS1307_RTC_STM32_HAL

Contact: mateusz@msalamon.pl
21 changes: 19 additions & 2 deletions Src/DS1307.c
@@ -1,12 +1,13 @@
/*
* DS1307.c
*
* The MIT License.
* Created on: 4.09.2019
* Author: Mateusz Salamon
* Contact: mateusz@msalamon.pl
*
* Website:
* GitHub:
* Website: https://msalamon.pl/dalsze-zmagania-z-rtc-ds1307-i-pcf8563-na-stm32/
* GitHub: https://github.com/lamik/DS1307_RTC_STM32_HAL
*/
#include "main.h"
#include "DS1307.h"
Expand Down Expand Up @@ -138,6 +139,22 @@ void DS1307_GetDateTime(RTCDateTime *DateTime)
}
#endif

void DS1307_ReadRAM(uint8_t Address, uint8_t *Value, uint8_t Length)
{
if((Address < DS1307_REG_RAM_START) || (Address > DS1307_REG_RAM_END)) return;
if((Address + Length + DS1307_REG_RAM_START) > DS1307_REG_RAM_END) return;

HAL_I2C_Mem_Read(hi2c_ds1307, DS1307_ADDRESS, Address, 1, Value, Length, DS1307_I2C_TIMEOUT);
}

void DS1307_WriteRAM(uint8_t Address, uint8_t *Value, uint8_t Length)
{
if((Address < DS1307_REG_RAM_START) || (Address > DS1307_REG_RAM_END)) return;
if((Address + Length + DS1307_REG_RAM_START) > DS1307_REG_RAM_END) return;

HAL_I2C_Mem_Write(hi2c_ds1307, DS1307_ADDRESS, Address, 1, Value, Length, DS1307_I2C_TIMEOUT);
}

void DS1307_Init(I2C_HandleTypeDef *hi2c)
{
hi2c_ds1307 = hi2c;
Expand Down
14 changes: 8 additions & 6 deletions Src/main.c
Expand Up @@ -15,6 +15,13 @@
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*
* Created on: 4.09.2019
* Author: Mateusz Salamon
* Contact: mateusz@msalamon.pl
*
* Website: https://msalamon.pl/dalsze-zmagania-z-rtc-ds1307-i-pcf8563-na-stm32/
* GitHub: https://github.com/lamik/DS1307_RTC_STM32_HAL
*/
/* USER CODE END Header */

Expand Down Expand Up @@ -170,25 +177,20 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == DS1307_INT_Pin)
{
HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_SET);
DS1307_ReceiveDateTimeDMA();
HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_RESET);
}
}

void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
{HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_SET);
{
DS1307_CalculateDateTime(&r);
HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_RESET);
}
#else
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == DS1307_INT_Pin)
{
HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_SET);
DS1307_GetDateTime(&r);
HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_RESET);
}
}
#endif
Expand Down

0 comments on commit 54fa7b2

Please sign in to comment.