#include "stm32f10x.h" #include "USART.h" unsigned char it_active=1; int stop; ////////////////////// ADC u32 ADCValue1; /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define ADC1_DR_Address ((uint32_t)0x4001244C) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; __IO uint32_t ADC_DualConvertedValueTab[3000]; /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); void GPIO_Configuration(void); // Variablen zum Splitten der ADC-Werte #define lowMask ((uint32_t)0xFFFF) #define highMask ((uint32_t)0xFFFF0000) u32 ADClow1=0; u32 ADChigh1=0; u32 ADClow2=0; u32 ADChigh2=0; char blar = 0X50; // Protokollvariablen zur Busübertragung u32 Protokoll[4]; #define Bit0to6 ((uint32_t)0x7F) #define Bit7to11 ((uint32_t)0xF80) #define Bit0to1 ((uint32_t)0x3) #define Bit2to8 ((uint32_t)0x1FC) #define Bit9to11 ((uint32_t)0xE00) // Protokoll Codierung int ADC1bit = 0x1; //0b00000001; int ADC2bit = 0x2; //0b00000010; int ADC3bit = 0x4; //0b00000100; int ADC4bit = 0x8; //0b00001000; int konst5to11 = 0xFE0; // 0b0000111111100000; int konst0to4 = 0x1F; // 0b0000000000011111; int konst10to11 = 0xC00; // 0b0000110000000000; int konst3to9 = 0x3F8; // 0b0000001111111000; int konst0to2 = 0x7; // 0b0000000000000111; int konst8to11 = 0xF00; // 0b0000111100000000; int konst1to7 = 0xFE; // 0b0000000011111110; int konst0to0 = 0x1; // 0b0000000000000001; int konst6to11 = 0xFC0; // 0b0000111111000000; int konst0to5 = 0x3F; // 0b0000000000111111; int konst0to6 = 0x7F; //0b01111111; int konst0to1 = 0x3; //0b00000011; int konst2to6 = 0x7C; //0b01111100; int konst0to3 = 0xF; //0b00001111; int konst4to6 = 0x70; //0b01110000; int konst6to6 = 0x40; //0b01000000; int StartBit = 0x80; //0b10000000; // Protokollbytes int PROTOKOLLBYTE1 = 0; int PROTOKOLLBYTE2 = 0; int PROTOKOLLBYTE3 = 0; int PROTOKOLLBYTE4 = 0; int PROTOKOLLBYTE5 = 0; int PROTOKOLLBYTE6 = 0; int PROTOKOLLBYTE7 = 0; int PROTOKOLLBYTE8 = 0; int CODIERWERT1 = 0; int CODIERWERT2 = 0; int CODIERWERT3 = 0; int CODIERWERT4 = 0; int ADCBits = 0x78; //0b01111000; int TimeBits = 0x7; //0b00000111; // Protokoll Byte Empfangen uint16_t GetStatusbyte = 0; int GetKANALWAHL = 0; int GetWANDLUNGSZEIT = 0; int MikroProtokoll(int ABTASTWERT1, int ABTASTWERT2, int ABTASTWERT3, int ABTASTWERT4, int KANALWAHL, int WANDLUNGSZEIT); ///////////////////////////////////////////////////////////////////////////////////// //int test; int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ USART2Init(); // char highBits1; // char lowBits1; // char highBits2; // char lowBits2; //char test4[10]; /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DualConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 3000; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 Channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_71Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC2 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC2, &ADC_InitStructure); /* ADC2 regular channels configuration */ ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_13, 2, ADC_SampleTime_71Cycles5); /* Enable ADC2 external trigger conversion */ ADC_ExternalTrigConvCmd(ADC2, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable Vrefint channel17 */ /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 reset calibaration register */ ADC_ResetCalibration(ADC2); /* Check the end of ADC2 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC2 calibaration */ ADC_StartCalibration(ADC2); /* Check the end of ADC2 calibration */ while(ADC_GetCalibrationStatus(ADC2)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* Test on DMA1 channel1 transfer complete flag */ while(!DMA_GetFlagStatus(DMA1_FLAG_TC1)); /* Clear DMA1 channel1 transfer complete flag */ DMA_ClearFlag(DMA1_FLAG_TC1); //int low=0XFFFF; //int high=0XFFFF0000; //int bitlowcomp = 0X00FF; //int bithighcomp = 0XFF00; int j=0; while (1) { /* if(USART_GetFlagStatus(USART2,USART_FLAG_RXNE) == SET){ GetStatusbyte = USART_ReceiveData(USART2); GetKANALWAHL = (GetStatusbyte & ADCBits)>>3; GetWANDLUNGSZEIT = GetStatusbyte & TimeBits; USART_ClearFlag(USART2, USART_FLAG_RXNE); } */ ADCValue1 = ADC_DualConvertedValueTab[j]; ADChigh1 = (ADC_DualConvertedValueTab[j] & highMask)>> 16; ADClow1 = (ADC_DualConvertedValueTab[j] & lowMask); j++; ADChigh2 = (ADC_DualConvertedValueTab[j] & highMask)>> 16; ADClow2 = (ADC_DualConvertedValueTab[j] & lowMask); // test= ADChigh1 >>4; // USART_SendData(USART2, test); // while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); MikroProtokoll(ADClow1, ADClow2, ADChigh1, ADChigh2, 1, GetWANDLUNGSZEIT); if(j<2998){ j++; } else{ j=0; } } } /** * @brief Configures the different system clocks. * @param None * @retval None */