further digging into i2c

pull/87/head
RobertGawron 2019-07-20 17:12:17 +01:00
rodzic c89fda1658
commit 1fb9d3e5bf
5 zmienionych plików z 82 dodań i 30 usunięć

Wyświetl plik

@ -521,7 +521,7 @@ void CLK_ITConfig(CLK_IT_TypeDef CLK_IT, FunctionalState NewState)
* @param ClockPrescaler Specifies the HSI or CPU clock divider to apply. * @param ClockPrescaler Specifies the HSI or CPU clock divider to apply.
* @retval None * @retval None
*/ */
#if 0 #if 1
void CLK_SYSCLKConfig(CLK_Prescaler_TypeDef CLK_Prescaler) void CLK_SYSCLKConfig(CLK_Prescaler_TypeDef CLK_Prescaler)
{ {
/* check the parameters */ /* check the parameters */

Wyświetl plik

@ -64,7 +64,7 @@
* @param None * @param None
* @retval None * @retval None
*/ */
#if 0 #if 1
void I2C_DeInit(void) void I2C_DeInit(void)
{ {
I2C->CR1 = I2C_CR1_RESET_VALUE; I2C->CR1 = I2C_CR1_RESET_VALUE;
@ -255,7 +255,7 @@ void I2C_GeneralCallCmd(FunctionalState NewState)
* This parameter can be any of the @ref FunctionalState enumeration. * This parameter can be any of the @ref FunctionalState enumeration.
* @retval None * @retval None
*/ */
#if 0 #if 1
void I2C_GenerateSTART(FunctionalState NewState) void I2C_GenerateSTART(FunctionalState NewState)
{ {
/* Check function parameters */ /* Check function parameters */
@ -280,7 +280,7 @@ void I2C_GenerateSTART(FunctionalState NewState)
* This parameter can be any of the @ref FunctionalState enumeration. * This parameter can be any of the @ref FunctionalState enumeration.
* @retval None * @retval None
*/ */
#if 0 #if 1
void I2C_GenerateSTOP(FunctionalState NewState) void I2C_GenerateSTOP(FunctionalState NewState)
{ {
/* Check function parameters */ /* Check function parameters */
@ -460,7 +460,7 @@ uint8_t I2C_ReceiveData(void)
* This parameter can be any of the @ref I2C_Direction_TypeDef enumeration. * This parameter can be any of the @ref I2C_Direction_TypeDef enumeration.
* @retval None * @retval None
*/ */
#if 0 #if 1
void I2C_Send7bitAddress(uint8_t Address, I2C_Direction_TypeDef Direction) void I2C_Send7bitAddress(uint8_t Address, I2C_Direction_TypeDef Direction)
{ {
/* Check function parameters */ /* Check function parameters */
@ -480,7 +480,7 @@ void I2C_Send7bitAddress(uint8_t Address, I2C_Direction_TypeDef Direction)
* @param Data : Byte to be sent. * @param Data : Byte to be sent.
* @retval None * @retval None
*/ */
#if 0 #if 1
void I2C_SendData(uint8_t Data) void I2C_SendData(uint8_t Data)
{ {
/* Write in the DR register the data to be sent */ /* Write in the DR register the data to be sent */
@ -602,7 +602,7 @@ void I2C_SendData(uint8_t Data)
* - SUCCESS: Last event is equal to the I2C_EVENT * - SUCCESS: Last event is equal to the I2C_EVENT
* - ERROR: Last event is different from the I2C_EVENT * - ERROR: Last event is different from the I2C_EVENT
*/ */
#if 0 #if 1
ErrorStatus I2C_CheckEvent(I2C_Event_TypeDef I2C_Event) ErrorStatus I2C_CheckEvent(I2C_Event_TypeDef I2C_Event)
{ {
__IO uint16_t lastevent = 0x00; __IO uint16_t lastevent = 0x00;

Wyświetl plik

@ -17,7 +17,7 @@
void ApplicationBuilder_Init() void ApplicationBuilder_Init()
{ {
ClockConfigurator_Init(); // ClockConfigurator_Init();
TimerConfigurator_Init(); TimerConfigurator_Init();
Logger_Init(); Logger_Init();
@ -27,7 +27,7 @@ void ApplicationBuilder_Init()
enableInterrupts(); enableInterrupts();
UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG); // UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);
} }
void ApplicationBuilder_Run() void ApplicationBuilder_Run()
@ -42,5 +42,7 @@ void ApplicationBuilder_Run()
void ApplicationBuilder_Tick() void ApplicationBuilder_Tick()
{ {
//Logger_Tick(); // Logger_Tick();
VoltageSensorActualValue_GeMeasurementData(0);
} }

Wyświetl plik

@ -6,7 +6,7 @@
*/ */
#include "Logger.h" #include "Logger.h"
#include <stdio.h> //#include <stdio.h>
#include "stm8s_uart1.h" #include "stm8s_uart1.h"
#include "PinoutConfiguration.h" #include "PinoutConfiguration.h"
@ -20,7 +20,7 @@ void assert_failed(uint8_t* file, uint32_t line)
(void)file; (void)file;
(void)line; (void)line;
printf("[error] asset failed %s %d\r\n", file, line); //printf("[error] asset failed %s %d\r\n", file, line);
while (TRUE) while (TRUE)
{ {
@ -40,7 +40,7 @@ void Logger_Init()
void Logger_Tick() void Logger_Tick()
{ {
printf ("ok "); // printf ("ok ");
} }

Wyświetl plik

@ -8,32 +8,82 @@
#include "VoltageSensorActualValue.h" #include "VoltageSensorActualValue.h"
#include "UserInterface.h" #include "UserInterface.h"
#include "stm8s_i2c.h" #include "stm8s_i2c.h"
#include <stdio.h> #include "stm8s_i2c.h"
#define I2C_SPEED 100000 #include "stm8s.h"
#define I2C_ADDRESS 0x68
// // MCP3425 I2C address is 0x68(104) #define I2C_ADDRESS 0x68 // MCP3425 I2C address is 0x68(104)
static void GPIO_setup(void);
void VoltageSensorActualValue_Init() void VoltageSensorActualValue_Init()
{ {
//printf("start\n"); CLK_DeInit();
I2C_Cmd( ENABLE);
/* I2C Initialize */ CLK_HSECmd(DISABLE);
I2C_Init(I2C_SPEED, I2C_ADDRESS, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16); CLK_LSICmd(DISABLE);
CLK_HSICmd(ENABLE);
while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
/* Enable Buffer and Event Interrupt*/
// I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_EVT | I2C_IT_BUF) , ENABLE);
#if 1 // assert fails here CLK_ClockSwitchCmd(ENABLE);
/* While the bus is busy */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV2);
#endif
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI,
DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);
GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_OUT_OD_HIZ_FAST);
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_OD_HIZ_FAST);
I2C_DeInit();
I2C_Init(100000,
I2C_ADDRESS,
I2C_DUTYCYCLE_2,
I2C_ACK_CURR,
I2C_ADDMODE_7BIT,
(CLK_GetClockFreq() / 1000000));
I2C_Cmd(ENABLE);
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
} }
bool VoltageSensorActualValue_GeMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData) bool VoltageSensorActualValue_GeMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData)
{ {
// printf("a\r\n");
I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
I2C_Send7bitAddress(I2C_ADDRESS, I2C_DIRECTION_TX);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(1);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(ENABLE);
// while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
//printf("b\r\n");
return TRUE; return TRUE;
} }
void GPIO_setup(void)
{
GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_OUT_OD_HIZ_FAST);
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_OD_HIZ_FAST);
}