Esempio n. 1
0
void init() {
    SystemInit();

    // Init the LEDs 
    GPIO_Config();                     

    // For FreeRTOS 
    NVIC_Config();

    // Init for debuging
    USART_Config();

    // LED Controller Init
    LEDDecoderInit();

    // Open CRC for emWin
    CRC_Init();    

    // LCD
    STM324xG_LCD_Init();
    sEE_Init();        

    // Touch Screen
    TSC_Config();     

    // emWin
    GUI_Init();      

    // File System
    file_system_init();
}
Esempio n. 2
0
/**
  * @brief  User callback that manages the Timeout error.
  * @param  pDevInitStruct .
  * @retval None.
  */
uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
{  
  /* Deinitialize peripheral */
  sEE_DeInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]) ;
  
  /* Initialize peripherals for communication with sEE */
  sEE_StructInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]);
  sEE_Init(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); 
    
  sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState = sEE_STATE_ERROR;
    
  return CPAL_PASS;   
}
Esempio n. 3
0
/**
  * @brief  User callback that manages the I2C device errors.
  * @note   Make sure that the define USE_SINGLE_ERROR_CALLBACK is uncommented in
  *         the cpal_conf.h file, otherwise this callback will not be functional.
  * @param  pDevInitStruct. 
  * @param  DeviceError.
  * @retval None
  */  
void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError)
{
  /* Stop timeout countdown */ 
  sEE_DevStructures[pDevInstance]->sEE_CPALStructure->wCPAL_Timeout  = CPAL_I2C_TIMEOUT_DEFAULT;  
  
  /* Deinitialize peripheral */
  sEE_DeInit(sEE_DevStructures[pDevInstance]) ;
  
  /* Initialize peripherals for communication with sEE */
  sEE_StructInit(sEE_DevStructures[pDevInstance]);
  sEE_Init(sEE_DevStructures[pDevInstance]); 
    
  sEE_DevStructures[pDevInstance]->sEEState = sEE_STATE_ERROR;
}
/**
  * @brief  Basic management of the timeout situation.
  * @param  None.
  * @retval 0.
  */
uint32_t sEE_TIMEOUT_UserCallback(void)
{
  /* The following code allows I2C error recovery and return to normal communication
     if the error source doesn’t still exist (ie. hardware issue..) */
  
  /* Reinitialize all resources */
  sEE_DeInit();
  sEE_Init();

  /* At this stage the I2C error should be recovered and device can communicate
     again (except if the error source still exist).
     User can implement mechanism (ex. test on max trial number) to manage situation
     when the I2C can't recover from current error. */
  
  return 0;
}
Esempio n. 5
0
/**
  * @brief  User callback that manages the I2C device errors.
  * @note   Make sure that the define USE_SINGLE_ERROR_CALLBACK is uncommented in
  *         the cpal_conf.h file, otherwise this callback will not be functional.
  * @param  pDevInitStruct. 
  * @param  DeviceError.
  * @retval None
  */ 
void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError)
{  
  /* Generate STOP */
  __CPAL_I2C_HAL_STOP(pDevInstance);
  
  LCD_DisplayStringLine(Line6, (uint8_t*)" Device Err occurred ");
  
  /* Deinitialize peripheral */
  sEE_DeInit(sEE_DevStructures[pDevInstance]) ;
  
  /* Initialize peripheral To communication with sEE and IOE and TempSensor*/
  sEE_StructInit(sEE_DevStructures[pDevInstance]);
  sEE_Init(sEE_DevStructures[pDevInstance]); 
  
  /* Initialize sEE state */
  if ((sEE_DevStructures[pDevInstance]->sEEState == sEE_STATE_WRITING)\
    || (sEE_DevStructures[pDevInstance]->sEEState == sEE_STATE_READING))
  {      
    sEE_DevStructures[pDevInstance]->sEEState = sEE_STATE_ERROR;
  }  
}
Esempio n. 6
0
/**
  * @brief  User callback that manages the Timeout error.
  * @param  pDevInitStruct .
  * @retval None.
  */
uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
{
  /* Generate STOP */
  __CPAL_I2C_HAL_STOP(pDevInitStruct->CPAL_Dev);
  
  LCD_DisplayStringLine(Line7, (uint8_t*)"Timeout Err occurred ");
  
  /* Deinitialize peripheral */
  sEE_DeInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]) ;
  
  /* Initialize peripheral to communication with sEE and IOE and TempSensor */
  sEE_StructInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]);
  sEE_Init(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); 
  
  /* Initialize sEE state */
  if ((sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState == sEE_STATE_WRITING)\
    || (sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState == sEE_STATE_READING))
  {    
    sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState = sEE_STATE_ERROR;
  }
  
  return CPAL_PASS;
}
Esempio n. 7
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void SPI_EEPROM_Example(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */

  /* Initialize the SPI EEPROM driver ----------------------------------------*/
  sEE_Init();

  /* First write in the memory followed by a read of the written data --------*/
  /* Write on SPI EEPROM from sEE_WRITE_ADDRESS1 */
  sEE_WriteBuffer(Tx1Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1);

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();

  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE1;

  /* Read from SPI EEPROM from sEE_READ_ADDRESS1 */
  sEE_ReadBuffer(Rx1Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead));

  /* Check if the data written to the memory is read correctly */
  TransferStatus1 = Buffercmp(Tx1Buffer, Rx1Buffer, BUFFER_SIZE1);

  /* Second write in the memory followed by a read of the written data -------*/
  /* Write on SPI EEPROM from sEE_WRITE_ADDRESS2 */
  sEE_WriteBuffer(Tx2Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2);

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();

  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE2;

  /* Read from SPI EEPROM from sEE_READ_ADDRESS2 */
  sEE_ReadBuffer(Rx2Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead));

  /* Check if the data written to the memory is read correctly */
  TransferStatus2 = Buffercmp(Tx2Buffer, Rx2Buffer, BUFFER_SIZE2);

#ifdef ENABLE_LCD_MSG_DISPLAY
  /* Initialize the LCD screen for information display */
  STM32303C_LCD_Init();
  LCD_Clear(LCD_COLOR_BLUE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_0, "SMT32F30x FW Library");
  LCD_DisplayStringLine(LCD_LINE_1, "   EEPROM Example   ");

  /* TransferStatus1 = PASSED, if the transmitted and received data
  to/from the EEPROM are the same */
  /* TransferStatus1 = FAILED, if the transmitted and received data
     to/from the EEPROM are different */
  if (TransferStatus1 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED  ");
  }

  /* TransferStatus2 = PASSED, if the transmitted and received data
  to/from the EEPROM are the same */
  /* TransferStatus2 = FAILED, if the transmitted and received data
  to/from the EEPROM are different */
  if (TransferStatus2 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED  ");
  }
#endif /* ENABLE_LCD_MSG_DISPLAY */

  /* Free all used resources */
  sEE_DeInit();

  while (1)
  {
  }
}
Esempio n. 8
0
File: main.c Progetto: vdalex/hamsdr
int main(void)
{
    //uint8_t Rx1_Buffer[BUFFER_SIZE1];
    volatile uint16_t NumDataRead = 0;
    volatile	uint16_t symbol;
    uint8_t command_buffer[10]= {0xe2,0xeb,0x81,120,0xc6,0xaf,0x88,0xb0,0x00,0x10};
    uint32_t xtal_value;

    /*
    0: 0xe2 - 11100010 - System  Reset
    1: 0xeb - 11101011 - Set LCD BIAS ratio [b1:b0]
    2: 0x81 - 10000001 - Set VBIAS potentiometer
    3: 0x50 - 01010000 - VBIAS potentiometer value
    4: 0xc6 - 11000110 - Set LCD Mapping Control [b2:b1]
    5: 0xaf - 10101111 - Set display ENABLE [b0]

    6: 0x89 - 10001001 - Set RAM adress Control [b2:b0]
    7: 0xb0 - 10110000 - Set Page Adress [b3:b0]
    8: 0x00 - 00000000 - Set Column Adress LSB [b3:b0]
    9: 0x10 - 00010000 - Set Column Adress MSB [b3:b0]
    */

    uint32_t decimal[8];

//uint8_t string0[]="Display Works Fine";
//uint8_t tune.tune_freq_vis[]="14000000"; /*Start Frequency*/
//uint8_t string2[]="FREQUENCY";
//uint8_t string3[]="HAM RADIO BAND";
    uint8_t string4[]="20m  USB  2800Hz x100";/*BAND MODE FILTER GAIN*/
//uint8_t string5[]="MODE SSB USB";
//uint8_t string6[]="GAIN 1000";
    uint8_t string7[]="PRE:Off ATT:20 AGC:S";

    uint8_t data_buffer[132];
    uint8_t data_buffer1[132];
    uint8_t data_buffer2[132];
    uint8_t data_buffer3[132];
    uint8_t si570_buf[11];
    uint32_t bit_order;
    uint8_t current_pointer;
    uint8_t k, n, sp, lzs_flag, symb_width, enc1_pulse_ccw, enc1_pulse_cw,enc2_pulse_ccw, enc2_pulse_cw, show_it;
    uint8_t option_select, sub_option_select;
    uint8_t n1;
    uint8_t hs_div_code;
    uint32_t i,j/*,noise_filter_button*/;
    uint8_t display_menu;
    uint8_t offcet_x;


    extern menu_struct_t menu[MAX_MENU_QTY];
    extern band_struct_t band_menu[MAX_BAND_QTY];
    extern mode_struct_t mode_menu[MAX_MODE_QTY];
    extern filter_struct_t filter_menu[MAX_FILTER_QTY];
    extern gain_struct_t gain_menu;
    extern tune_struct_t tune;

    RCC_ClocksTypeDef RCC_Clocks;
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* SysTick end of count event each 10ms */

//if (FLASH_OB_GetRDP()!=SET)
//{
//	FLASH_OB_Unlock(); /*enable the FLASH option control register access*/
//	FLASH_OB_RDPConfig(OB_RDP_Level_1); /*SET RDP=1*/
//	FLASH_OB_Launch(); /*launch the Option Bytes programming process*/
//	FLASH_OB_Lock(); /*disable the FLASH option control register*/
//}

    /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);
    STM_EVAL_LEDInit(LED5);
    STM_EVAL_LEDInit(LED6);

    /* Initialize user button STM324xG-EVAL board *****************/
    STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

    STM_EVAL_ControlInit(CODEC_RESET);
    BOARD_GPIO_Init(); /*encoder input init*/

    /* Turn on LEDs available on STM324xG-EVAL **********************************/
    STM_EVAL_LEDOff(LED3);
    STM_EVAL_LEDOff(LED4);
    STM_EVAL_LEDOff(LED5);
    STM_EVAL_LEDOff(LED6);

    STM_EVAL_ControlOn(CODEC_RESET);
    Delay (300);
    STM_EVAL_ControlOff(CODEC_RESET);

    xtal_value=(uint32_t)114197425;/*0x6cfd9c8*/
    freq_code_old=0;
    NumDataRead = 1;

    /* Initialize the I2C EEPROM driver ----------------------------------------*/
    sEE_Init();
    /* Initialize the CODEC driver*/

    EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S);
    EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 255, I2S_AudioFreq_48k);
    EVAL_AUDIO_Play(sound, 96);

    /*Continuous Beep from codec*/
    Codec_WriteRegister(0x1E, 0xC0);


    Delay (100);
    LCD_Write_Command(0x70, command_buffer, 1);
    Delay (10);
    LCD_Write_Command(0x70, (command_buffer+1), 5);
    Delay (10);
    n=0xA1;/*100 Hz frame rate*/
    LCD_Write_Command(0x70, &n, 1);

    bit_order=0x989680; /*1e+7 decimal*/

    for (j=0; j<8; j++) /*filling array for decimal to binary conversion*/
    {
        decimal[j]=bit_order;
        bit_order=bit_order/10;
    }

    /*Clear display*/
    symbol=0x00;
    for (j=0; j<8; j++)
    {
        for (i=0; i<131; i++)
        {
            data_buffer[i]=symbol;
        }

        LCD_Write_Command(0x70, (command_buffer+6), 4);
        Delay (10);
        LCD_Write_Data(0x70, data_buffer, (uint32_t)132);
        command_buffer[7]++;
        Delay (10);
    }


    si570_buf[6]=0x10;/*freeze DCO reg 137*/
    si570_buf[7]=0x00;/*unfreeze DCO reg 137*/
    si570_buf[8]=0x40;/*status new dco reg 135*/
    si570_buf[9]=0x20;/*freeze M bit reg 135*/
    si570_buf[10]=0x00;/*unfreeze M bit reg 135*/

//  command_buffer[7]=0xb3;

// 	LCD_Write_Command(0x70, (command_buffer+6), 4);

    freq2=0;
    i=5;
    j=0;
    k=0;
    sp=0;
    display_menu=0;

    show_it=1;	/*initial display*/
    display_menu=1;
    current_menu=0;


    old_value=new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK;

    while (1)
    {
        new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK;

        if (new_value!=old_value)
        {
            current_pointer=1;
            enc1_old_value=old_value&ENCODER1_MASK;
            enc2_old_value=old_value&ENCODER2_MASK;

            enc1_new_value=new_value&ENCODER1_MASK;
            enc2_new_value=new_value&ENCODER2_MASK;

            if (enc2_new_value!=enc2_old_value)
            {
                current_pointer=0;
                if ((enc2_old_value&ENCODER2_A_MASK)!=((enc2_new_value<<1)&ENCODER2_A_MASK))/*==ENCODER2_MASK*/
                {
                    STM_EVAL_LEDToggle(LED3);
                    enc2_pulse_ccw=0;
                    enc2_pulse_cw++;
                }
                else
                {
                    STM_EVAL_LEDToggle(LED6);
                    enc2_pulse_cw=0;
                    enc2_pulse_ccw++;
                }
                //old_value=new_value;

                if (enc2_pulse_cw==4)				/*increment*/
                {
                    if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/
                    {
                        menu[current_menu].menu_current_state++;
                        if(menu[current_menu].menu_current_state>menu[current_menu].menu_states_qty-1)	/*control if submenu<MAX_SUBMENU*/
                        {
                            menu[current_menu].menu_current_state=0;
                        }
                        /*apply handler with action parameter*/

                    }
                    else /*change menu*/
                    {
                        current_menu++;
                        if (current_menu>MAX_MENU_QTY-1)  /*control if menu<MAX_MENU*/
                        {
                            current_menu=0;
                        }
                    }
                    enc2_pulse_cw=0;
                    enc2_pulse_ccw=0;
                    display_menu=1;
                    if (current_menu==0) show_it=1;
                }
                else
                {
                    if (enc2_pulse_ccw==4)			/*decrement*/
                    {
                        if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/
                        {
                            menu[current_menu].menu_current_state--;
                            if (menu[current_menu].menu_current_state<0)
                            {
                                menu[current_menu].menu_current_state=menu[current_menu].menu_states_qty-1;
                            }
                            /*apply handler with action parameter*/

                        }
                        else /*change menu*/
                        {
                            current_menu--;/*control if menu<MAX_MENU*/
                            if (current_menu<0)
                            {
                                current_menu=MAX_MENU_QTY-1;
                            }
                        }
                        enc2_pulse_cw=0;
                        enc2_pulse_ccw=0;
                        display_menu=1;
                        if (current_menu==0) show_it=1;
                    }

                }
            }
            if (current_pointer==1)
            {
                if ((enc1_old_value&ENCODER1_A_MASK)!=((enc1_new_value<<1)&ENCODER1_A_MASK))/*==ENCODER1_MASK*/
                {
                    STM_EVAL_LEDToggle(LED5);
                    enc1_pulse_ccw=0;
                    enc1_pulse_cw++;
                }
                else
                {
                    STM_EVAL_LEDToggle(LED4);
                    enc1_pulse_cw=0;
                    enc1_pulse_ccw++;
                }
                old_value=new_value;
                /*--------------------------------------------------*/
                if (enc1_pulse_cw==4)				/*increment*/
                {
                    if (STM_EVAL_PBGetState(BUTTON_USER)==0)
                    {
                        for (j=1; j<8-i; j++)
                        {
                            tune.tune_freq_vis[i+j]=0x30;
                        }

                        enc1_pulse_cw=0;
                        enc1_pulse_ccw=0;

                        if ((tune.tune_freq_vis[i]&0x0f)==0x09)
                        {
                            tune.tune_freq_vis[i]=0;
                            j=1;
                            while ((tune.tune_freq_vis[i-j]&0x0f)==0x09)
                            {
                                tune.tune_freq_vis[i-j]=0;
                                j++;
                            }
                            tune.tune_freq_vis[i-j]++;
                        }
                        else
                        {
                            tune.tune_freq_vis[i]++;
                        }

                        show_it=1;
                    }
                    else
                    {
                        enc1_pulse_cw=0;
                        enc1_pulse_ccw=0;

                        if (i==7)
                        {
                            i=0;
                        }
                        else
                        {
                            i++;
                        }
                        show_it=1;

                    }
                }
                /*--------------------------------------------------*/


                else
                {
                    if (enc1_pulse_ccw==4)		/*decrement*/

                    {
                        if (STM_EVAL_PBGetState(BUTTON_USER)==0)
                        {
                            for (j=1; j<8-i; j++)
                            {
                                tune.tune_freq_vis[i+j]=0x30;
                            }

                            enc1_pulse_cw=0;
                            enc1_pulse_ccw=0;

                            if ((tune.tune_freq_vis[i]&0x0f)==0x00)
                            {
                                tune.tune_freq_vis[i]=9;
                                j=1;
                                while ((tune.tune_freq_vis[i-j]&0x0f)==0x00)
                                {
                                    tune.tune_freq_vis[i-j]=9;
                                    j++;
                                }
                                tune.tune_freq_vis[i-j]--;
                            }
                            else
                            {
                                tune.tune_freq_vis[i]--;
                            }
                        }
                        else
                        {
                            enc1_pulse_cw=0;
                            enc1_pulse_ccw=0;
                            if (i==0)
                            {
                                i=7;
                            }
                            else
                            {
                                i--;
                            }
                            show_it=1;
                        }
                    }
                    show_it=1;
                }
            }

            if (display_menu==1) /*build menu buffer*/
            {
                display_menu=0;

                pp1=menu[current_menu].pFunc(MODIFY);

                for (j=0; j<MAX_MENU_QTY; j++)
                {
                    k=0;
                    offcet_x=menu[j].menu_x_pos;
                    pp1=menu[j].pFunc(DISPLAY);
                    if (j==current_menu)
                    {
                        data_buffer2[k+offcet_x]=0xFF;
                        data_buffer3[k+offcet_x]=0x07;
                        k++;
                        while ((*pp1)!=0)
                        {
                            for (jj=0; jj<5; jj++)
                            {
                                symbol=symboltable[(*pp1)-0x20][jj];
                                data_buffer2[k+offcet_x]=~(symbol<<2);/*Fill Upper buffer*/
                                data_buffer3[k+offcet_x]=~((symbol>>6)|0xF8);
                                k++;
                            }
                            data_buffer2[k+offcet_x]=0xFF;
                            data_buffer3[k+offcet_x]=0x07;
                            k++;
                            pp1++;
                        }
                        data_buffer2[k+offcet_x]=0xFF;
                        data_buffer3[k+offcet_x]=0x07;
                    }
                    else
                    {
                        data_buffer2[k+offcet_x]=0x00;
                        data_buffer3[k+offcet_x]=0x00;
                        k++;
                        while ((*pp1)!=0)
                        {
                            for (jj=0; jj<5; jj++)
                            {
                                symbol=symboltable[(*pp1)-0x20][jj];
                                data_buffer2[k+offcet_x]=(uint8_t)symbol<<2;/*Fill Upper buffer*/
                                data_buffer3[k+offcet_x]=(uint8_t)symbol>>6;
                                k++;
                            }
                            data_buffer2[k+offcet_x]=0x00;
                            data_buffer3[k+offcet_x]=0x00;
                            k++;
                            pp1++;
                        }
                        data_buffer2[k+offcet_x]=0x00;
                        data_buffer3[k+offcet_x]=0x00;
                    }
                }
Esempio n. 9
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
*/
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_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */    

#ifdef ENABLE_LCD_MSG_DISPLAY
  /* Initialize the LCD screen for information display */
#ifdef USE_STM32L152D_EVAL
  STM32L152D_LCD_Init();
#else
  STM32L152_LCD_Init();
#endif 
  LCD_Clear(LCD_COLOR_BLUE);  
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_0, "SMT32L1xx FW Library");
  LCD_DisplayStringLine(LCD_LINE_1, "   EEPROM Example   ");
#endif /* ENABLE_LCD_MSG_DISPLAY */  
  
  /* Initialize the I2C EEPROM driver ----------------------------------------*/
  sEE_Init();  

  /* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from sEE_WRITE_ADDRESS1 */
  sEE_WriteBuffer(Tx1_Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1); 

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();  
  
  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE1;
  
  /* Read from I2C EEPROM from sEE_READ_ADDRESS1 */
  sEE_ReadBuffer(Rx1_Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead)); 


  /* Starting from this point, if the requested number of data is higher than 1, 
     then only the DMA is managing the data transfer. Meanwhile, CPU is free to 
     perform other tasks:
  
    // Add your code here: 
    //...
    //...

     For simplicity reasons, this example is just waiting till the end of the 
     transfer. */
 
#ifdef ENABLE_LCD_MSG_DISPLAY  
  LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 Ongoing ");
#endif /* ENABLE_LCD_MSG_DISPLAY */ 
  
  /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler 
    resets the variable holding the number of data to be read) */
  while (NumDataRead > 0)
  {}  
  
  /* Check if the data written to the memory is read correctly */
  TransferStatus1 = Buffercmp(Tx1_Buffer, Rx1_Buffer, BUFFER_SIZE1);
  /* TransferStatus1 = PASSED, if the transmitted and received data 
     to/from the EEPROM are the same */
  /* TransferStatus1 = FAILED, if the transmitted and received data 
     to/from the EEPROM are different */
#ifdef ENABLE_LCD_MSG_DISPLAY  
  if (TransferStatus1 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED  ");
  }  
#endif /* ENABLE_LCD_MSG_DISPLAY */  

  /* Second write in the memory followed by a read of the written data -------*/
  /* Write on I2C EEPROM from sEE_WRITE_ADDRESS2 */
  sEE_WriteBuffer(Tx2_Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2); 

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();  
  
  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE2;  
  
  /* Read from I2C EEPROM from sEE_READ_ADDRESS2 */
  sEE_ReadBuffer(Rx2_Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead));


  /* Starting from this point, if the requested number of data is higher than 1, 
     then only the DMA is managing the data transfer. Meanwhile, CPU is free to 
     perform other tasks:
     
    // Add your code here: 
    //...
    //...

     For simplicity reasons, this example is just waiting till the end of the 
     transfer. */

#ifdef ENABLE_LCD_MSG_DISPLAY   
  LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 Ongoing ");
#endif /* ENABLE_LCD_MSG_DISPLAY */  
  
  /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler 
    resets the variable holding the number of data to be read) */
  while (NumDataRead > 0)
  {}
  
  /* Check if the data written to the memory is read correctly */
  TransferStatus2 = Buffercmp(Tx2_Buffer, Rx2_Buffer, BUFFER_SIZE2);
  /* TransferStatus2 = PASSED, if the transmitted and received data 
     to/from the EEPROM are the same */
  /* TransferStatus2 = FAILED, if the transmitted and received data 
     to/from the EEPROM are different */
#ifdef ENABLE_LCD_MSG_DISPLAY   
  if (TransferStatus2 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED  ");
  }  
#endif /* ENABLE_LCD_MSG_DISPLAY */
  
  /* Free all used resources */
  sEE_DeInit();

  while (1)
  {
  }
}
Esempio n. 10
0
int main(void){
	
	//configure push-button interrupts
	PB_Config();
	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);

	
	
	//======You need to develop the following functions======
	//Note: these are just placeholders; function definitions are at bottom of this file
	//configure real-time clock
	RTC_Config();
	
	//configure external push-buttons and interrupts
	ExtPB_Config();
	ExtPBNum2();
	
	
	//main program
	
	LCD_Clear(LCD_COLOR_WHITE);
		
	//line=0;
	//Display a string in one line, on the first line (line=0)
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Init EEPROM...");
	//line++;
	
	//i2c_init(); //initialize the i2c chip
	sEE_Init();  

	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "done..."); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Writing...");
	//line++;
	
	
	/* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from memLocation */
  //sEE_WriteBuffer(&Tx1_Buffer, memLocation,1); 

  /* Wait for EEPROM standby state */
  //sEE_WaitEepromStandbyState();  
 
  
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Reading...");
  /* Read from I2C EEPROM from memLocation */
  //sEE_ReadBuffer(&Rx1_Buffer, memLocation, (uint16_t *)(&NumDataRead)); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Comparing...");  
	//line++;
	
	
	//if(Tx1_Buffer== Rx1_Buffer){
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Success!");  
	//}else{
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Mismatch!"); 
	//}
	
	//main loop
	while(1){
		RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);
		hours = RTC_TimeStructure.RTC_Hours;
		minutes = RTC_TimeStructure.RTC_Minutes;
		seconds = RTC_TimeStructure.RTC_Seconds;

		sprintf(time,"%0.2d:%0.2d:%0.2d",hours,minutes,seconds);
		LCD_DisplayStringLine(LINE(6),  (uint8_t *) time); 
		
		if(UBPressed == 1){
			
			toBeSaved = time[7];
			sEE_WriteBuffer(&toBeSaved, memLocation+1,1); 
			sEE_WaitEepromStandbyState();  
			
			sEE_ReadBuffer(&Rx1_Buffer, memLocation+1, (uint16_t *)(&NumDataRead)); 
			saved[0] = Rx1_Buffer;

			
			
			LCD_DisplayStringLine(LINE(7),  (uint8_t *) saved);
			
			UBPressed = 0;
			PB_Config();
			
		}
		if(EB1Pressed == 1 && state == 0){
			state = 1;
			EB1Pressed = 0;
			ExtPB_Config();
		}
		if(EB1Pressed == 1 && state == 1){
			state = 2;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 2){
			state = 3;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 3){
			state = 0;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB2Pressed == 1 && state == 1){
			
			RTC_TimeStructure.RTC_Hours = hours + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 2){
			
			RTC_TimeStructure.RTC_Minutes = minutes + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 3){
			
			RTC_TimeStructure.RTC_Seconds = seconds + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		
	}
}