void SPI_RTCWriteTime(RTC_TIME Time) { BYTE Cmd; Cmd = RTC_SECONDS | WRITEMASK; SPISendData(RTCDeviceHandle, &Cmd, 1, (BYTE*)&Time, sizeof(RTC_TIME)); }
/***************************************************************************** Function: void SPIRTCSRAMWriteArray(BYTE* vData, WORD wLen) Summary: Writes an array of bytes to the SPI Flash part. Description: This function writes an array of bytes to the SPI SRAM part. Precondition: SPIRTCSRAMInit and SPIRTCSRAMBeginWrite have been called. Parameters: vData - The array to write to the next memory location wLen - The length of the data to be written Returns: None Remarks: See Remarks in SPIRTCSRAMBeginWrite for important information about Flash memory parts. ***************************************************************************/ void SPI_RTC_SRAMWriteArray(BYTE bAddress, BYTE *vData, WORD wLength) { BYTE Cmd[2]; // Ignore operations when the destination is NULL or nothing to read if(vData == NULL || wLength == 0) return; Cmd[0] = SRAM_ADDRES | WRITEMASK; Cmd[1] = bAddress; SPISendCmd(RTCDeviceHandle, Cmd, 2); Cmd[0] = SRAM_DATA | WRITEMASK; SPISendData(RTCDeviceHandle, Cmd, 1, vData, wLength); }
/** * @brief Main program * @param None * @retval None */ int main(void) { __IO uint16_t i; __IO uint16_t *ptr; __IO uint16_t tmp1; __IO uint16_t tmp2; uint32_t scpcnt; uint32_t scpwait; uint32_t scptpos; /* RCC Configuration */ RCC_Config(); /* GPIO Configuration */ GPIO_Config(); /* TIM Configuration */ TIM_Config(); /* NVIC Configuration */ NVIC_Config(); /* DAC Configuration */ DAC_Config(); /* SPI Configuration */ SPI_Config(); /* USART Configuration */ USART_Config(115200); /* Calibrate LC Meter */ LCM_Calibrate(); // /* Update bluetooth baudrate */ // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // USART3_puts("AT\0"); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount) // { // if ((USART3->SR & USART_FLAG_RXNE) != 0) // { // STM32_CMD.BTBuff[i] = USART3->DR; // i++; // } // } // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount); // USART3_puts("AT+BAUD8\0"); // STM32_CMD.Cmd = STM32_CMD.TickCount; // while (STM32_CMD.Cmd == STM32_CMD.TickCount) // { // if ((USART3->SR & USART_FLAG_RXNE) != 0) // { // STM32_CMD.BTBuff[i] = USART3->DR; // i++; // } // } // while (1) // { // } while (1) { USART3_getdata((uint8_t *)&STM32_CMD.Cmd,4); switch (STM32_CMD.Cmd) { case CMD_LCMCAL: LCM_Calibrate(); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_LCMCAP: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_LCMIND: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_6); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_putdata((uint8_t *)&STM32_CMD.STM32_LCM.FrequencyCal0,sizeof(STM32_LCMTypeDef)); break; case CMD_FRQCH1: GPIO_ResetBits(GPIOD, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_FRQCH2: GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_1); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_FRQCH3: GPIO_ResetBits(GPIOD, GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_SCPSET: USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_getdata((uint8_t *)&STM32_CMD.STM32_SCP.ADC_Prescaler,sizeof(STM32_SCPTypeDef)); /* Scope magnify */ i = (STM32_CMD.STM32_SCP.ScopeMag & 0x07) << 3; GPIO_SetBits(GPIOE,(i ^ 0x38)); GPIO_ResetBits(GPIOE,i); /* Set V-Pos */ DAC_SetChannel1Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP.ScopeVPos); /* Set Trigger level */ DAC_SetChannel2Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP.ScopeTriggerLevel); if (STM32_CMD.STM32_SCP.ADC_TripleMode) { /* DMA Configuration */ DMA_TripleConfig(STM32_CMD.STM32_SCP.ADC_SampleSize); /* ADC Configuration */ ADC_TripleConfig(STM32_CMD.STM32_SCP.ADC_Prescaler, STM32_CMD.STM32_SCP.ADC_TwoSamplingDelay); } else { /* DMA Configuration */ DMA_SingleConfig(STM32_CMD.STM32_SCP.ADC_SampleSize); /* ADC Configuration */ ADC_SingleConfig(STM32_CMD.STM32_SCP.ADC_Prescaler,STM32_CMD.STM32_SCP.ADC_SampleTime); } if (STM32_CMD.STM32_SCP.ScopeTrigger == 2) { /* Rising edge */ TIM5->CCER &= ~0x2; } else { /* Falling edge */ TIM5->CCER |= 0x2; } if (STM32_CMD.STM32_SCP.ScopeTrigger) { /* Wait for trigger */ scpcnt = TIM5->CNT; scpwait = STM32_CMD.TickCount + 2; while (scpcnt == TIM5->CNT && scpwait != STM32_CMD.TickCount); } /* Start ADC1 Software Conversion */ ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART; i = 0; while (i < 30000) { i++; } /* Since BlueTooth is slower than the lowest sampling rate there is no need to wait */ SendCompressedBuffer((uint32_t *)SCOPE_DATAPTR, STM32_CMD.STM32_SCP.ADC_SampleSize / 4); /* Done */ ADC->CCR=0; ADC1->CR2=0; ADC2->CR2=0; ADC3->CR2=0; break; case CMD_SCP2SET: STM_EVAL_LEDToggle(LED4); USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); USART3_getdata((uint8_t *)&STM32_CMD.STM32_SCP2.SampleRateSet,sizeof(STM32_SCP2TypeDef)); /* Scope magnify */ i = ((uint32_t)STM32_CMD.STM32_SCP2.Mag & 0x07) << 3; GPIO_SetBits(GPIOE,(i ^ 0x38)); GPIO_ResetBits(GPIOE,i); /* Set V-Pos */ DAC_SetChannel1Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP2.VPos); /* Set Trigger level */ DAC_SetChannel2Data(DAC_Align_12b_R, STM32_CMD.STM32_SCP2.TriggerLevel); /* Get number of samples needed */ SampleSize = GetScopeSampleSize(); if (STM32_CMD.STM32_SCP2.Triple) { /* DMA Configuration */ DMA_TripleConfig(SampleSize); /* ADC Configuration */ ADC_TripleConfig((uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet >> 4,(uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet & 0xF); } else { /* DMA Configuration */ DMA_SingleConfig(SampleSize); /* ADC Configuration */ ADC_SingleConfig(((uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet >> 3) & 0x3,(uint32_t)STM32_CMD.STM32_SCP2.SampleRateSet & 0x7); } /* Trigger configuration */ if (STM32_CMD.STM32_SCP2.Trigger == 2) { /* Rising edge */ TIM5->CCER &= ~0x2; } else { /* Falling edge */ TIM5->CCER |= 0x2; } if (STM32_CMD.STM32_SCP2.Trigger) { /* Wait for trigger */ scpcnt = TIM5->CNT; scpwait = STM32_CMD.TickCount + 2; while (scpcnt == TIM5->CNT && scpwait != STM32_CMD.TickCount); } /* Start ADC1 Software Conversion */ ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART; /* Reset wavedata */ ScopeResetWave((uint32_t *)SCOPE_WAVEPTR,SCOPE_MAXWAVESIZE); ScopeResetWave((uint32_t *)SCOPE_COUNTPTR,SCOPE_MAXWAVESIZE); /* Wait until DMA transfer complete */ while (DMA_GetFlagStatus(DMA2_Stream0, DMA_FLAG_TCIF0) == RESET); /* Done sampling */ ADC->CCR=0; ADC1->CR2=0; ADC2->CR2=0; ADC3->CR2=0; ScopeSetWaveData((uint32_t *)SCOPE_WAVEPTR, (uint32_t *)SCOPE_COUNTPTR, (uint16_t *)SCOPE_DATAPTR); scptpos = 0; if (STM32_CMD.STM32_SCP2.Trigger) { scptpos = ScopeFindTrigger((uint16_t *)SCOPE_DATAPTR); } /* Send wave data */ SendCompressedBuffer((uint32_t *)(SCOPE_DATAPTR + scptpos * 2), (uint32_t)STM32_CMD.STM32_SCP2.PixDiv * (uint32_t)STM32_CMD.STM32_SCP2.nDiv * 2 / 4); STM_EVAL_LEDToggle(LED4); break; case CMD_HSCSET: GPIO_ResetBits(GPIOD, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOD, GPIO_Pin_0); USART3_getdata((uint8_t *)&STM32_CMD.STM32_HSC.HSCSet,sizeof(STM32_HSCTypeDef)); TIM4->ARR = STM32_CMD.STM32_HSC.HSCSet; TIM4->CCR2 = (STM32_CMD.STM32_HSC.HSCSet+1) / 2; TIM4->PSC = STM32_CMD.STM32_HSC.HSCDiv; USART3_putdata((uint8_t *)&STM32_CMD.STM32_FRQ.Frequency,sizeof(STM32_FRQTypeDef)); break; case CMD_DDSSET: USART3_getdata((uint8_t *)&STM32_CMD.STM32_DDS.DDS_Cmd,sizeof(STM32_DDSTypeDef)); if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_PHASESET) { SPISendData(DDS_PHASESET); SPISendData32(STM32_CMD.STM32_DDS.DDS__PhaseAdd); } else if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_WAVESET) { SPISendData(DDS_WAVESET); SPISendData(STM32_CMD.STM32_DDS.DDS_Wave); SPISendData(STM32_CMD.STM32_DDS.DDS_Amplitude); SPISendData(STM32_CMD.STM32_DDS.DDS_DCOffset); } else if (STM32_CMD.STM32_DDS.DDS_Cmd == DDS_SWEEPSET) { SPISendData(DDS_SWEEPSET); SPISendData(STM32_CMD.STM32_DDS.SWEEP_Mode); SPISendData(STM32_CMD.STM32_DDS.SWEEP_Time); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Step); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Min); SPISendData32(STM32_CMD.STM32_DDS.SWEEP_Max); } break; case CMD_LGASET: USART3_getdata((uint8_t *)&STM32_CMD.STM32_LGA.DataBlocks,sizeof(STM32_LGATypeDef)); /* Set the Prescaler value */ TIM8->PSC = STM32_CMD.STM32_LGA.LGASampleRateDiv; /* Set the Autoreload value */ TIM8->ARR = STM32_CMD.STM32_LGA.LGASampleRate; TIM8->CNT = STM32_CMD.STM32_LGA.LGASampleRate-1; DMA_LGAConfig(); TIM_DMACmd(TIM8, TIM_DMA_Update, ENABLE); /* DMA2_Stream1 enable */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable timer */ TIM8->CR1 |= TIM_CR1_CEN; while (DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_HTIF1) == RESET); /* Half done */ USART3_putdata((uint8_t *)LGA_DATAPTR, STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2); while (DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_TCIF1) == RESET); /* Done */ USART3_putdata((uint8_t *)(LGA_DATAPTR + STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2), STM32_CMD.STM32_LGA.DataBlocks * 1024 / 2); TIM_Cmd(TIM8, DISABLE); DMA_DeInit(DMA2_Stream1); break; case CMD_WAVEUPLOAD: USART3_getdata((uint8_t *)WAVE_DATAPTR,4096); SPISendData(DDS_WAVEUPLOAD); ptr = (uint16_t *)WAVE_DATAPTR; i = 2048; while (i--) { SPISendData(*ptr); ptr++; } STM_EVAL_LEDToggle(LED4); break; }
void SPI_RTCWriteRegister(BYTE bAddress, BYTE vData) { BYTE Cmd; Cmd = bAddress | WRITEMASK; SPISendData(RTCDeviceHandle, &Cmd, 1, &vData, 1); }
static void M25P16WriteRegister(uint8_t Value) { SPISendData(&FLASH_SPI, &Value, 1); }