//void CPAL_I2C_DMARXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) //{ } //void CPAL_I2C_DMARXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct) //{ } void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError) { if ((DeviceError & CPAL_I2C_ERR_AF) != 0) {mRedON; mWaitms(2000);} if ((DeviceError & CPAL_I2C_ERR_BERR) != 0) {mGreenON; mWaitms(2000);} if ((DeviceError & CPAL_I2C_ERR_ARLO) != 0) {mYellowON;mWaitms(2000);} if ((DeviceError & CPAL_I2C_ERR_OVR) != 0) {mBlueON; mWaitms(2000);} if ((DeviceError & CPAL_I2C_ERR_TIMEOUT) != 0) {mWhiteON; mWaitms(2000);} uint32_t i; for(i=0; i<10; i++) { mGreenOFF; mRedOFF; mYellowON; mBlueOFF; mWhiteON; mWait(800000); mGreenON; mRedON; mYellowOFF; mBlueON; mWhiteOFF; mWait(800000); } mBusRestart(); }
int main( void ) { uint8_t d = 0x34,rxbuf = 0X23; mInit(); // I2C_config(); SPI_config(); debug_setup(); ADC_A_config(); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //M4 DIRECTION GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //M3 DIRECTION GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); TIMA_config(100, 20,10); // timer1 channel 1 PA8 TIMB_config(100, 20,10); // timer2 channel 3 PA9 TIMC_config(100, 20,10); // timer15 channel 1 PB14 TIMD_config(100, 20,10); // timer2 channel 2 PA1 // first 2 numbers // // in this function are not doing anything while(1) { GPIO_ResetBits(GPIOA, GPIO_Pin_0); GPIO_ResetBits(GPIOB, GPIO_Pin_15); // debug_write_ch(0XAB); mBlueTOGGLE; mGreenTOGGLE; mRedTOGGLE; mWaitms(300); GPIO_SetBits(GPIOA, GPIO_Pin_0); GPIO_SetBits(GPIOB, GPIO_Pin_15); /* Test EOC flag */ while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); /* Get ADC1 converted data */ ADC1ConvertedValue =ADC_GetConversionValue(ADC1); debug_write_u16(ADC1ConvertedValue,10); debug_write_line(" "); // mWaitms(300); // I2C_write_1byte(SLAVE_ADDR2,254,22); // rxbuf = I2C_read_1byte(SLAVE_ADDR,254); // debug_write_ch(rxbuf); // rxbuf = I2C_read_1byte(SLAVE_ADDR1,254); // debug_write_ch(rxbuf); // rxbuf = I2C_read_1byte(SLAVE_ADDR2,254); // debug_write_ch(rxbuf); // TIM_SetCompare2 ( TIM2,1); // mWaitms(300); // TIM_SetCompare2 ( TIM2,0); // mWaitms(1000); // SPI_SendData8(SPI1, d); // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); // rxbuf = SPI_ReceiveData8(SPI1); } }
int main (void) { mInit(); mBusInit(); mUSBInit(); mWhiteOFF; mRedOFF; mGreenON; for (uint8_t i = 0; i < COMMAND_SIZE + 1; i++) command_buffer[i] = '\0'; // initialize command buffer bool sd_initialized = false; reconnect: while (bDeviceState != CONFIGURED); sd_initialized = m_sd_init(); mWaitms (1000); welcome_screen(); if (!sd_initialized) printf ("ERROR: Could not initialize microSD card\r\n"); printf ("> "); for (;;) { if (bDeviceState != CONFIGURED) { goto reconnect; } const int rchar = getchar(); if (rchar < 0) continue; const char c = (char)rchar; if (c == '\n' || c == '\r') { // received 'enter' printf ("\r\n"); if (sd_initialized) { process_command(); if (fatal_error) sd_initialized = false; } else { if (m_sd_init()) { fatal_error = false; sd_initialized = true; process_command(); if (fatal_error) sd_initialized = false; } else { printf ("ERROR: Could not initialize microSD card: error code %d\r\n", m_sd_error_code); } } command_ptr = command_buffer; // reset the current command length to 0 printf ("> "); } else if (c == 8 || c == 127) { // received backspace (or delete) if (command_ptr > command_buffer) { command_ptr--; putchar (27); // escape printf ("[1D"); // move the cursor back 1 character putchar (27); printf ("[K"); // erase from the cursor position to the end of the line } } else if (c >= 32 && c < 127) { // received a printable character or escape if (command_ptr < command_buffer + COMMAND_SIZE) { *command_ptr = c; command_ptr++; putchar (c); } else { // out of command space: send bell putchar (7); } } } return 0; }