Solar collector pump controller


Solar collector pump controller based on MCU ARM STM32Fo

Video sample

Solar collector pump controller

 

Solar collector pump controller inside

 

Solar collector pump controller final

Example how get temperature from DS18s20 via UART

int main(void){

int i;

   UART_Config();

while(1){

OW_Reset(USART1);
OW_SendByte(0xCC);              // kreipiames i visus daviklius
OW_SendByte(0x44);             // skaiciuoja temperatura visi davikliai

delay_ms(750);                           // laukiam skaiciavimu

// ***************** T0 *****************************************
OW_Reset(USART1);
OW_SendByte(0x55);              // kreipiames i pirma davikli ID0 {0x10, 0x31, 0x19, 0xCB, 0x02, 0x08, 0x00, 0x3A};

for(i = 0; i < 8; i++){
OW_SendByte(ID0[i]);             // siunciam ID
}

OW_SendByte(0xBE);               // prasom temperaturos duomenu pirmo daviklio
for(i=0; i < 9; i++)                        // nuskaitom temperatura
{
temp[i] = OW_ReadByte();
}

t0 = ((float)temp[0] – 0.25 + ((float)(temp[7] – temp[6]) / (float)temp[7])) /2 ;
if (temp[1] != 0) t0 *= -1;
if ((t0 <=-56) || (t0 >= 126)) t0 = t0_old;
t0_old = t0;

// ***************** T0 END ***********************************

// ***************** T1 *****************************************
OW_Reset(USART1);
OW_SendByte(0x55);                    // kreipiames i antra davikli ID0 {0x10, 0xB1, 0x26, 0xCB, 0x02, 0x08, 0x00, 0x3B};

for(i = 0; i < 8; i++)
{
OW_SendByte(ID1[i]);              // siunciam ID
}

OW_SendByte(0xBE);                  // prasom temperaturos duomenu

for(i=0; i < 9; i++)                           // nuskaitom temperatura
{
temp[i] = OW_ReadByte();
}

t1 = ((float)temp[0] – 0.25 + ((float)(temp[7] – temp[6]) / (float)temp[7])) /2 ;
if (temp[1] != 0) t1 *= -1;

if ((t1 <=-56) || (t1 >= 126)) t1 = t1_old;
t1_old = t1;
// ***************** T1 END ***********************************

}

}

 

void OW_SendByte(uint8_t byte)
{
int i;
for(i=0; i<8; i++)
{
if((byte & (1<<i) ) != 0)
{
SerialPutChar(0xFF);
}else{
SerialPutChar(0x00);
}
}
}

uint8_t OW_ReadByte(void)
{
uint16_t result=0;
int i;

for(i=0; i<8; i++)
{
SerialPutChar(0xFF);
delay_ms(1);
if(USART_ReceiveData(USART1) == 0xFF)
{
result |= (1<<i);
}

}
return result;
}

 

uint8_t OW_Reset(USART_TypeDef* USARTx) {
uint8_t ow_presence;
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USARTx, &USART_InitStructure);

USART_Cmd(USARTx,ENABLE);
delay_ms(100);

USART_ClearFlag(USARTx, USART_FLAG_TC);

USART_SendData(USARTx, 0xF0);
while (USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET);
ow_presence = USART_ReceiveData(USARTx);

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USARTx, &USART_InitStructure);

USART_Cmd(USARTx,ENABLE);
delay_ms(100);

if (ow_presence != 0xF0) {
return 1;
}

return 0;
}

 

void USART_Config(void){

USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

// Peripherial configuration
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // Enable GPIO clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // Enable USART clock

// GPIO configuration (USART2: PB6 Tx, PB7 Rx)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0); // Tx6
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0); // Rx7

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2; // 10Mhz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

// USART configuration
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);

// USART interrupt configuration
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

// Additional configuration
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_CM, ENABLE);

   USART_Cmd(USART1,ENABLE);

}

 

73! de LY3H


One response to “Solar collector pump controller”

  1. Hi,

    I am trying to run your code on STM32F0 with DS18b20 But its not working weel.

    Can you help me please.

    Thanks

Leave a Reply