Incompatible pointer assignment
Hi Guys,
I am writing a code to measure a pulsating DC voltage. All that I have decided to take 50 samples and take the highest one. Multiplying the peak value by a factor will give me the approximate RMS value. Please see my code. When built, an error “ Incompatible pointer assignment” shows.
#include "stm8s.h"
unsigned int max_v;
unsigned k;
unsigned int val[100];
void Clock_Config(void) {
CLK->ICKR |= CLK_ICKR_HSIEN; // Enable HSI
while (!(CLK->ICKR & CLK_ICKR_HSIRDY)); // Wait for stabilization
CLK->CKDIVR = 0x00; // HSI 16MHz / 1 = 16MHz
CLK->SWR = 0xE1; // Use HSI as master clock
}
void adc_init(void) {
ADC1 -> CR1 = 0x40;
ADC1 -> CR2 = 0x08;
ADC1 -> TDRH = 0xFF;
ADC1 -> TDRL = 0xFF;
ADC1 -> CR1 |= ADC1_CR1_ADON;
}
uint16_t read_mains_value(void) {
unsigned int value;
ADC1 -> CSR = 0x05;
ADC1_StartConversion();
while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == FALSE);
value = ADC1_GetConversionValue();
ADC1_ClearFlag(ADC1_FLAG_EOC); //
return value;
}
void delay_us (int us) //Function Definition
{
int i =0 ;
int j=0;
for (i=0; i<=us; i++)
{
for (j=0; j<16; j++) // Nop = Fosc/4
_asm("nop"); //Perform no operation //assembly code <span style="white-space:pre"> </span>
}
}
void main(void)
{
Clock_Config();
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_IN_FL_NO_IT);
adc_init();
for ( k = 0; k<50; k++ ) {
val[k] = read_mains_value;
delay_us(200);
}
max_v = 0;
for ( k = 0; k < 50; k++) {
if (val[k] > max_v) {
max_v = val[k];
}
val[k] = 0;
}
