I am using the nPM2100 EK dev board with a stm32wl5MOC.
Using the example from the bare metal drivers, I adapted the code to my board.
I can succesfully read and set bytes on the i2c bus to the nPM2100.
Following the example, I am only using the timer part. I set the GPIO as such:
#include "main.h"
#include "dma.h"
#include "i2c.h"
#include "app_lorawan.h"
#include "rtc.h"
#include "usart.h"
#include "gpio.h"
#include "stm32wl_utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stm32_uart.h"
#include "LmHandler.h"
#include "lora_app.h"
#include "radio_board_if.h"
#include "sys_app.h"
#include "nPM2100.h"
#include "gpio_npm2100.h"
#define NPM2100_EVENT_SYS_TIMER_EXPIRY 2
#define PMIC_INT_OUT_PIN 1 // Set this to the correct pin number for your hardware
#define BIT(n) (1U << (n))
void SystemClock_Config(void);
void npm2100_ldo_setup(struct i2c_dev *dev);
void npm2100_TimerSetup(struct i2c_dev *dev, uint32_t period_ms);
int main(void)
{
int8_t rslt = 0;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_RTC_Init();
MX_I2C1_Init();
uint32_t events = 0;
struct i2c_ctx npm2100_ctx;
struct i2c_dev npm2100_dev = { .addr = 0x74, .context = &npm2100_ctx };
uint8_t timer_reg = 0;
i2c_init(&npm2100_dev, &hi2c1);
HAL_Delay(100);
rslt = nPM2100_Init(&npm2100_dev);
if (rslt != 0) {
printf("nPM2100 Init Error!\r\n");
}
else {
printf("nPM2100 initialized successfully.\r\n");
}
HAL_Delay(100);
npm2100_TimerSetup(&npm2100_dev, 3000);
printf("nPM2100 timer set to 3 seconds.\r\n");
rslt = nPM2100_StartTimer(&npm2100_dev);
if (rslt != 0) {
printf("nPM2100 start timer error: %d\r\n", rslt);
}
while (1){
rslt = nPM2100_GetRegister(&npm2100_dev, 0xb7, &timer_reg);
printf("timer status: 0x%02X\r\n", timer_reg);
rslt = nPM2100_ProcessEvents(&npm2100_dev, &events);
if (events & BIT(NPM2100_EVENT_SYS_TIMER_EXPIRY)) {
rslt = nPM2100_StartTimer(&npm2100_dev);
printf("nPM2100 timer expired, timer restarted.\r\n");
}
HAL_Delay(100);
}
}
void npm2100_TimerSetup(struct i2c_dev *dev, uint32_t period_ms)
{
int rslt;
rslt = mfd_npm2100_stop_timer(dev);
if (rslt != 0) {
printf("nPM2100 stop timer error: %d\r\n", rslt);
}
HAL_Delay(3);
rslt = mfd_npm2100_set_timer(dev, period_ms, NPM2100_TIMER_MODE_GENERAL_PURPOSE);
if (rslt != 0) {
printf("nPM2100 set timer error: %d\r\n", rslt);
}
rslt = mfd_npm2100_enable_events(dev, BIT(NPM2100_EVENT_SYS_TIMER_EXPIRY));
if (rslt != 0) {
printf("nPM2100 enable events error: %d\r\n", rslt);
}
rslt = gpio_npm2100_config(dev, PMIC_INT_OUT_PIN, NPM2100_GPIO_MODE_IRQ_LOW, NPM2100_GPIO_CONFIG_OUTPUT | NPM2100_GPIO_CONFIG_PULLUP);
if (rslt != 0) {
printf("nPM2100 GPIO config error: %d\r\n", rslt);
}
}
