kopia lustrzana https://github.com/RobertGawron/IonizationChamber
further digging into i2c
rodzic
c89fda1658
commit
1fb9d3e5bf
|
@ -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.
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void CLK_SYSCLKConfig(CLK_Prescaler_TypeDef CLK_Prescaler)
|
||||
{
|
||||
/* check the parameters */
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void I2C_DeInit(void)
|
||||
{
|
||||
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.
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void I2C_GenerateSTART(FunctionalState NewState)
|
||||
{
|
||||
/* Check function parameters */
|
||||
|
@ -280,7 +280,7 @@ void I2C_GenerateSTART(FunctionalState NewState)
|
|||
* This parameter can be any of the @ref FunctionalState enumeration.
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void I2C_GenerateSTOP(FunctionalState NewState)
|
||||
{
|
||||
/* Check function parameters */
|
||||
|
@ -460,7 +460,7 @@ uint8_t I2C_ReceiveData(void)
|
|||
* This parameter can be any of the @ref I2C_Direction_TypeDef enumeration.
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void I2C_Send7bitAddress(uint8_t Address, I2C_Direction_TypeDef Direction)
|
||||
{
|
||||
/* Check function parameters */
|
||||
|
@ -480,7 +480,7 @@ void I2C_Send7bitAddress(uint8_t Address, I2C_Direction_TypeDef Direction)
|
|||
* @param Data : Byte to be sent.
|
||||
* @retval None
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
void I2C_SendData(uint8_t Data)
|
||||
{
|
||||
/* 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
|
||||
* - ERROR: Last event is different from the I2C_EVENT
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
ErrorStatus I2C_CheckEvent(I2C_Event_TypeDef I2C_Event)
|
||||
{
|
||||
__IO uint16_t lastevent = 0x00;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
void ApplicationBuilder_Init()
|
||||
{
|
||||
ClockConfigurator_Init();
|
||||
// ClockConfigurator_Init();
|
||||
TimerConfigurator_Init();
|
||||
|
||||
Logger_Init();
|
||||
|
@ -27,7 +27,7 @@ void ApplicationBuilder_Init()
|
|||
|
||||
enableInterrupts();
|
||||
|
||||
UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);
|
||||
// UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);
|
||||
}
|
||||
|
||||
void ApplicationBuilder_Run()
|
||||
|
@ -42,5 +42,7 @@ void ApplicationBuilder_Run()
|
|||
|
||||
void ApplicationBuilder_Tick()
|
||||
{
|
||||
//Logger_Tick();
|
||||
// Logger_Tick();
|
||||
|
||||
VoltageSensorActualValue_GeMeasurementData(0);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "Logger.h"
|
||||
#include <stdio.h>
|
||||
//#include <stdio.h>
|
||||
#include "stm8s_uart1.h"
|
||||
#include "PinoutConfiguration.h"
|
||||
|
||||
|
@ -20,7 +20,7 @@ void assert_failed(uint8_t* file, uint32_t line)
|
|||
(void)file;
|
||||
(void)line;
|
||||
|
||||
printf("[error] asset failed %s %d\r\n", file, line);
|
||||
//printf("[error] asset failed %s %d\r\n", file, line);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ void Logger_Init()
|
|||
|
||||
void Logger_Tick()
|
||||
{
|
||||
printf ("ok ");
|
||||
// printf ("ok ");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,32 +8,82 @@
|
|||
#include "VoltageSensorActualValue.h"
|
||||
#include "UserInterface.h"
|
||||
#include "stm8s_i2c.h"
|
||||
#include <stdio.h>
|
||||
#define I2C_SPEED 100000
|
||||
#define I2C_ADDRESS 0x68
|
||||
// // MCP3425 I2C address is 0x68(104)
|
||||
#include "stm8s_i2c.h"
|
||||
#include "stm8s.h"
|
||||
|
||||
#define I2C_ADDRESS 0x68 // MCP3425 I2C address is 0x68(104)
|
||||
|
||||
static void GPIO_setup(void);
|
||||
|
||||
|
||||
void VoltageSensorActualValue_Init()
|
||||
{
|
||||
//printf("start\n");
|
||||
I2C_Cmd( ENABLE);
|
||||
CLK_DeInit();
|
||||
|
||||
CLK_HSECmd(DISABLE);
|
||||
CLK_LSICmd(DISABLE);
|
||||
CLK_HSICmd(ENABLE);
|
||||
while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
|
||||
|
||||
/* I2C Initialize */
|
||||
I2C_Init(I2C_SPEED, I2C_ADDRESS, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16);
|
||||
|
||||
/* Enable Buffer and Event Interrupt*/
|
||||
// I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_EVT | I2C_IT_BUF) , ENABLE);
|
||||
CLK_ClockSwitchCmd(ENABLE);
|
||||
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);
|
||||
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV2);
|
||||
|
||||
#if 1 // assert fails here
|
||||
/* While the bus is busy */
|
||||
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
|
||||
#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)
|
||||
{
|
||||
return TRUE;
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue