Ejemplo n.º 1
0
/**
  * @brief  Display Init (LCD)
  * @param  None
  * @retval None
  */
void Display_Init(void)
{
  /* Initialize the LCD */
  STM32303C_LCD_Init();

  /* Clear the LCD */ 
  LCD_Clear(White);

  /* Set the LCD Text size */
  LCD_SetFont(&Font8x12);

  /* Set the LCD Back Color and Text Color*/
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);

  /* Display */
  LCD_DisplayStringLine(LINE(0x13), (uint8_t*)"  ADC conversion example (Diff example)");

  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);

  LCD_DisplayStringLine(LINE(0), (uint8_t*)"STM32F303x CortexM4 ");
  LCD_DisplayStringLine(LINE(1), (uint8_t*)"   STM32303C-EVAL   ");
  
  /* Set the LCD Back Color and Text Color*/
  LCD_SetBackColor(White);
  LCD_SetTextColor(Blue);

  /* Display */
  LCD_DisplayStringLine(LINE(3),(uint8_t*)"  Turn RV2(PC.01)    ");
  LCD_DisplayStringLine(LINE(4),(uint8_t*)"   Potentiometer     ");
     
}
Ejemplo n.º 2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void COMP_PulseWidthMeasurement(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 TFT-LCD */
  STM32303C_LCD_Init();
  
  /* Clear the TFT-LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* DAC Channel1 configuration */
  DAC_Config();
  
  /* COMP1 Configuration */
  COMP_Config();
  
  /* TIM2 Configuration in input capture mode */
  TIM_Config();
  
  /* Displays PulseWidthMeasurement message on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);

  /* Infinite loop */
  while (1)
  {
    if (DisplayActive != 0)
    {
      /* Compute the pulse width in us */
      MeasuredPulse = (uint32_t)(((uint64_t) Capture * 1000000) / ((uint32_t)SystemCoreClock));
      
      /* Display measured pulse width on LCD */
      LCD_Display(MeasuredPulse);  
      DisplayActive = 0;
    }
  }
}
Ejemplo n.º 3
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)
  {
  }
}
Ejemplo n.º 4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void CAN_FIFOExtension(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 LCD */
  STM32303C_LCD_Init();      
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
    
  LCD_SetFont(&Font12x12);
  
  /* Display Messages on the the LCD */  
  LCD_DisplayStringLine(LINE(0x3), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
     
  /* CAN configuration */
  CAN_Config();
  
  /* Infinite loop */
  while(1)
  {
    while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED)
    { 
      if(KeyNumber == 41) KeyNumber = 0;
      
      Display_TransmittedMsg(KeyNumber);
      
      KeyNumber++;
      
      Delay();
      
      while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED)
      {
      }
    }
      if (MsgReceived != 0)
        {
            /* Display received the 6 messages on tghe LCD */
            Display_ReceivedMsg();
            MsgReceived = 0;
     
    }
  }
}
Ejemplo n.º 5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void RTC_StopWatch_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 LCD */
  STM32303C_LCD_Init();      
    
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 1 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Red);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Red);
  LCD_DrawFullRect(31, 292,264,34);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  LCD_DrawFullRect(33, 290 ,260,30);
  
  /* Configure the external interrupt "SEL", "RIGHT" and "LEFT" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_SEL,BUTTON_MODE_GPIO);
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();

  /* Set the LCD Text, Back Colors and Text size */
  LCD_SetTextColor(Black); 
  LCD_SetBackColor(Cyan);
  LCD_SetFont(&Font12x12);
  
  LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);
  
  LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3);
  
  /* Set text size */
  LCD_SetFont(&Font16x24);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  
  /* Initialize time Stucture */
  RTC_TimeStructInit(&RTC_TimeStruct); 

  /* Infinite loop */
  while (1)
  {
    /* Set the LCD Back Color and text size */
    LCD_SetFont(&Font16x24);
    LCD_SetBackColor(White);
    
    /* Check on the event 'start' */
    if(StartEvent != 0x0)
    {  
      /* Get the RTC sub second fraction */
      SecondFraction = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
      
      /* Get the Curent time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
      
      /* Refresh : Display the curent time and the sub second on the LCD  */
      RTC_Time_Display(37, Black , RTC_Get_Time(SecondFraction , &RTC_TimeStruct));
    }
    else
    {
      /* Re-initialize the Display time on the LCD */
      RTC_Time_InitDisplay();
    }  
  }
}
Ejemplo n.º 6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void COMP_LDR_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
     */

  uint8_t ldrlevel = 11, ldrlevelp = 0, daclevel = 0;
  uint16_t tmp = 0;

  /* Initialize the TFT-LCD */
  STM32303C_LCD_Init();
  
  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_BLACK);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_BLACK);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_WHITE);
  
  /* Displays Light dependent resistor (LDR) message on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* COMP Configuration */
  COMP_Config();
 
  /* DAC channel 1 Configuration */
  DAC_Config();
  
  
  /* Infinite loop */
  while (1)
  {
    for(daclevel = 0; daclevel < 11; daclevel++)
    {
      /* Set DAC Channel1 DHR register */
      DAC_SetChannel1Data(DAC_Align_12b_R, (uint16_t)(daclevel * 150));

      Delay((0xFFFF));
      /* Check on the Comp output level*/
      if (COMP_GetOutputLevel(COMP_Selection_COMP7) == COMP_OutputLevel_High)
      {
        ldrlevel--;
      }
    }

    switch(ldrlevel)
    {
    case 1:
      /* Displays MESSAGE on line 7 */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 0      ");
      break;
      
    case 2:
      /* Displays MESSAGE on line 7 */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 1      ");
      break;
      
    case 3:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 2      ");
      break;
      
    case 4:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 3      ");
      break;
      
    case 5:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 4      ");
      break;
      
    case 6:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 5      ");
      break;
      
    case 7:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 6      ");
      break;
      
    case 8:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 7      ");
      break;
      
    case 9:
      /* Displays MESSAGE on line 7 */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 8      ");
      break;
      
    case 10:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 9      ");
      break;
      
    case 11:
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 10     ");
      break;
      
    default :
      /* Displays MESSAGE on line 7  */
      LCD_DisplayStringLine(LINE(7), (uint8_t *)"       Level 0      ");
      ldrlevel = 1;
      break;
    }
    
    if(ldrlevelp != ldrlevel)
    {
      /* Set the LCD Text Color */
      LCD_SetTextColor(LCD_COLOR_WHITE);
      
      /* Displays a rectangle on the LCD */
      LCD_DrawRect(199, 311, 22, 302 );
      
      /* Set the LCD Back Color */
      LCD_SetBackColor(LCD_COLOR_BLACK);
      LCD_SetTextColor(LCD_COLOR_BLACK);
      LCD_DrawFullRect(200, 310, 300, 20);
      
      /* Set the LCD Text Color */
      LCD_SetTextColor(LCD_COLOR_YELLOW);
      
      /* Set the LCD Back Color */
      LCD_SetBackColor(LCD_COLOR_YELLOW);
      
      /* Displays a full rectangle */
      tmp = 30 * (ldrlevel-1);
      if (tmp ==0) tmp = 5;
      LCD_DrawFullRect(200, 310, tmp , 20);
    }
    
    ldrlevelp = ldrlevel;
    ldrlevel = 11;
    
    /* Set the LCD Back Color */
    LCD_SetBackColor(LCD_COLOR_BLACK);
  }

}
Ejemplo n.º 7
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_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */

  
  /* Initialize the LCD */
  STM32303C_LCD_Init();      
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font8x12);
  
  /* Display */
  LCD_DisplayStringLine(LINE(0x13), (uint8_t*)"  CAN CAN_DualFIFO using FIFO 0 and FIFO 1 ");
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  /* Set the LCD Text size */
  LCD_SetFont(&Font12x12);
  
  /* Display Messages on the LCD */  
  LCD_DisplayStringLine(LINE(0x7), (uint8_t *)MESSAGE2);
  LCD_DisplayStringLine(LINE(0x8), (uint8_t *)MESSAGE3);
                        
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 
  
  /* Configure Push button sel */
  STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); 
   
  /* CAN configuration */
  CAN_Config();
  
  /* Infinite loop */
  while(1)
  {
  }
}
Ejemplo n.º 8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void I2C_TSENSOR_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
  */
  
  uint32_t i = 0;
  
  /* Initialize the LCD */
  STM32303C_LCD_Init();
  
  /* Initialize the Temperature Sensor */
  TS751_Init();
  
  if (TS751_GetStatus() == SUCCESS)
  {
    /* Clear the LCD */
    LCD_Clear(LCD_COLOR_WHITE);
    
    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_BLUE);
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_GREEN);
    
    LCD_DisplayStringLine(LCD_LINE_0, "     Temperature    ");
    LCD_DisplayStringLine(LCD_LINE_8, " Check JP1 closed   ");
    
    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_WHITE);
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_BLACK);
    
    /* NVIC Configuration */
    NVIC_Config();
  
    /* Enables the I2C SMBus Alert feature */
    I2C_SMBusAlertCmd(I2C2, ENABLE);
    
    I2C_ClearFlag(I2C2, I2C_FLAG_ALERT);
    
    SMbusAlertOccurred = 0;
    
    /* Enable SMBus Alert interrupt */
    I2C_ITConfig(I2C2, I2C_IT_ERRI, ENABLE);
    
    /* Configure the Temperature sensor device STTS751 */
    TS751_WriteConfReg(0x0C);    
    
    /* Configure the Temperature Therm limit as 40°C */
    TS751_WriteReg(0x05, TEMPERATURE_TOS);   
    TS751_WriteReg(0x20, TEMPERATURE_TOS);   

    /* Configure the Temperature Thys limit as 20°C */
    TS751_WriteReg(0x07, TEMPERATURE_THYS);   
    TS751_WriteReg(0x21, TEMPERATURE_THYS);
    
    /* Infinite Loop */
    while (1)
    {
      /* Get double of Temperature value */
      TempValue = TS751_ReadTemp();
      
      if (TempValue <= 2048)
      {
        /* Positive temperature measured */
        TempCelsiusDisplay[4] = '+';
        /* Initialize the temperature sensor value */
        TempValueCelsius = TempValue;
      }
      else
      {
        /* Negative temperature measured */
        TempCelsiusDisplay[4] = '-';
        /* Remove temperature value sign */
        TempValueCelsius = 0x1000 - TempValue;
      }
      
      TempCelsius = 0;
      
      /* Calculate temperature digits in ÝC */
      if (TempValueCelsius & 0x01)
      {
        TempCelsius += 625;     
        
      }
      if (TempValueCelsius & 0x02)
      {
        TempCelsius += 1250;
        
      }
      if (TempValueCelsius & 0x04)
      {
        TempCelsius += 2500;
      }
      if (TempValueCelsius & 0x08)
      {
        TempCelsius += 5000;
      }
      
      TempCelsiusDisplay[9] = (TempCelsius / 1000) + 0x30;
      TempCelsiusDisplay[10] = ((TempCelsius % 1000) / 100) + 0x30;
      TempCelsiusDisplay[11] = (((TempCelsius % 1000) % 100) / 10)+ 0x30;
      TempCelsiusDisplay[12] = (((TempCelsius % 1000) % 100) % 10) + 0x30;
      
      TempValueCelsius >>= 4;

      TempCelsiusDisplay[5] = (TempValueCelsius / 100) + 0x30;
      TempCelsiusDisplay[6] = ((TempValueCelsius % 100) / 10) + 0x30;
      TempCelsiusDisplay[7] = ((TempValueCelsius % 100) % 10) + 0x30;
      
      TempValueCelsiusFloat = TempValueCelsius + (float) (TempCelsius/10000.0);
      
      if (TempValue > 2048)
      {
        if (((9 * TempValueCelsiusFloat) / 5) <= 32)
        {
          /* Convert temperature °C to Fahrenheit */
          TempValueFahrenheitFloat = abs ((int)(32 - ((9 * TempValueCelsiusFloat) / 5)));
          
          TempValueFahrenheit = (int) (TempValueFahrenheitFloat);
          
          /* Calculate temperature digits in °F */
          TempFahrenheitDisplay[5] = (TempValueFahrenheit / 100) + 0x30;
          TempFahrenheitDisplay[6] = ((TempValueFahrenheit % 100) / 10) + 0x30;
          TempFahrenheitDisplay[7] = ((TempValueFahrenheit % 100) % 10) + 0x30;
          /* Positive temperature measured */
          TempFahrenheitDisplay[4] = '+';
          
          TempFahrenheit = TempValueFahrenheitFloat - TempValueFahrenheit;
          
          TempFahrenheitDisplay[9] =  (int)(TempFahrenheit * 10) + 0x30;
          TempFahrenheitDisplay[10] = ((int)(TempFahrenheit * 100) % 10) + 0x30;
          TempFahrenheitDisplay[11] = ((int)(TempFahrenheit * 1000) % 10) + 0x30;
          TempFahrenheitDisplay[12] = ((int)(TempFahrenheit * 10000) % 10) + 0x30;       
        }
        else
        {
          /* Convert temperature °C to Fahrenheit */
          TempValueFahrenheitFloat = abs((int)(((9 * TempValueCelsiusFloat) / 5) - 32));
          
          TempValueFahrenheit = (int) (TempValueFahrenheitFloat);
          
          /* Calculate temperature digits in °F */
          TempFahrenheitDisplay[5] = (TempValueFahrenheit / 100) + 0x30;
          TempFahrenheitDisplay[6] = ((TempValueFahrenheit % 100) / 10) + 0x30;
          TempFahrenheitDisplay[7] = ((TempValueFahrenheit % 100) % 10) + 0x30;
          
          /* Negative temperature measured */
          TempFahrenheitDisplay[4] = '-';
          
          TempFahrenheit = TempValueFahrenheitFloat - TempValueFahrenheit;
          
          TempFahrenheitDisplay[9] =  (int)(TempFahrenheit * 10) + 0x30;
          TempFahrenheitDisplay[10] = ((int)(TempFahrenheit * 100) % 10) + 0x30;
          TempFahrenheitDisplay[11] = ((int)(TempFahrenheit * 1000) % 10) + 0x30;
          TempFahrenheitDisplay[12] = ((int)(TempFahrenheit * 10000) % 10) + 0x30;
        }
      }
      else
      {
        /* Convert temperature °C to Fahrenheit */
        TempValueFahrenheitFloat = ((9 * TempValueCelsiusFloat) / 5) + 32;
        
        TempValueFahrenheit = (int) (TempValueFahrenheitFloat);
        
        /* Calculate temperature digits in °F */
        TempFahrenheitDisplay[5] = (TempValueFahrenheit / 100) + 0x30;
        TempFahrenheitDisplay[6] = ((TempValueFahrenheit % 100) / 10) + 0x30;
        TempFahrenheitDisplay[7] = ((TempValueFahrenheit % 100) % 10) + 0x30;
        
        /* Positive temperature measured */
        TempFahrenheitDisplay[4] = '+';

        TempFahrenheit = TempValueFahrenheitFloat - TempValueFahrenheit;
        
        TempFahrenheitDisplay[9] =  (int)(TempFahrenheit * 10) + 0x30;
        TempFahrenheitDisplay[10] = ((int)(TempFahrenheit * 100) % 10) + 0x30;
        TempFahrenheitDisplay[11] = ((int)(TempFahrenheit * 1000) % 10) + 0x30;
        TempFahrenheitDisplay[12] = ((int)(TempFahrenheit * 10000) % 10) + 0x30;
      }
      /* Display Fahrenheit value on LCD */
      for (i = 0; i < 20; i++)
      {
        LCD_DisplayChar(LCD_LINE_6, (319 - (16 * i)), TempCelsiusDisplay[i]);
        LCD_DisplayChar(LCD_LINE_7, (319 - (16 * i)), TempFahrenheitDisplay[i]);
      }
      
      if ((SMbusAlertOccurred == 1) && ((TempValueCelsius > (TEMPERATURE_TOS-1)) && (TempValue < 2048)))
      {     
        Var = 1;
        /* Set the Back Color */
        LCD_SetBackColor(LCD_COLOR_BLUE);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_RED);
        LCD_DisplayStringLine(LCD_LINE_1, "Temp higher than 40C");
      }
      
      if ((SMbusAlertOccurred == 1) && ((TempValueCelsius < TEMPERATURE_THYS) || (TempValue > 2048)))
      {
        Var = 2;
        /* Set the Back Color */
        LCD_SetBackColor(LCD_COLOR_BLUE);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_RED);
        LCD_DisplayStringLine(LCD_LINE_1, "Temp lower than 20C ");  
      }
      
      if ((SMbusAlertOccurred == 1) && (TempValueCelsius < TEMPERATURE_TOS) && (Var == 1))
      {
        Var = 0;
        SMbusAlertOccurred = 0;
        Tmp = TS751_AlerteResponseAddressRead();
        
        /* Set the Back Color */
        LCD_SetBackColor(LCD_COLOR_WHITE);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_ClearLine(LCD_LINE_1);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_BLACK);  
      }
      
      if (((SMbusAlertOccurred == 1) && (TempValueCelsius > (TEMPERATURE_THYS-1)) && (Var == 2)) && (TempValue < 2048))
      {
        Var = 0;
        SMbusAlertOccurred = 0;
        Tmp = TS751_AlerteResponseAddressRead();
        
        /* Set the Back Color */
        LCD_SetBackColor(LCD_COLOR_WHITE);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_ClearLine(LCD_LINE_1);
        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_BLACK);       
      }     
    }
  }
Ejemplo 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_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
  */
 
  /* Configure Clocks */
  RCC_Config();

  /* Initialize LEDs, Key Button and LCD available on
  STM32303C-EVAL board *****************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Initialize the LCD */
  STM32303C_LCD_Init();

  /* Display message on  LCD ***********************************************/
  /* Clear the LCD */ 
  LCD_Clear(White);  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Yellow);
  LCD_DisplayStringLine(Line0, (uint8_t*)MESSAGE1);
  LCD_DisplayStringLine(Line1, (uint8_t*)MESSAGE2);
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);

  /* Configure the Push buttons in Polling mode */
  STM_EVAL_PBInit(BUTTON_KEY, Mode_GPIO);

  /* if STM32 device is set as Master */
#ifdef I2C_MASTER

  /* Configure and enable the systick timer to generate an interrupt each 1 ms */
  SysTick_Config((SystemCoreClock / 1000));

  /* Deinitialize I2Cx Device */ 
  CPAL_I2C_DeInit(&MASTERSTRUCTURE); 

  /* Initialize CPAL I2C structure parameters values */
  CPAL_I2C_StructInit(&MASTERSTRUCTURE);
  MASTERSTRUCTURE.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR;

#ifdef CPAL_I2C_DMA_PROGMODEL
  MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
 #error "Please select one of the programming model (in main.h)"
#endif

  /* Set I2C Speed */
  MASTERSTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = MASTER_I2C_TIMING;

  /* Select Master Mode */
  MASTERSTRUCTURE.CPAL_Mode = CPAL_MODE_MASTER; 

  /* Initialize I2Cx Device*/
  CPAL_I2C_Init(&MASTERSTRUCTURE); 

  /* Infinite loop */
  while(1)
  {
    /* Initialize Transfer parameters */
    MASTERSTRUCTURE.pCPAL_TransferTx = &sTxStructure;
    sTxStructure.wNumData = BufferSize;
    sTxStructure.pbBuffer = (uint8_t*)BufferTX;
    sTxStructure.wAddr1 = OWNADDRESS;

    /* Update LCD Display */
    LCD_SetBackColor(White);
    LCD_SetTextColor(Blue);    
    LCD_DisplayStringLine(Line8, (uint8_t*)MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line5, (uint8_t*)MESSAGE4);
    LCD_DisplayStringLine(Line6, (uint8_t*)MESSAGE5);

    /* wait until Key button is pushed */
    while(STM_EVAL_PBGetState(BUTTON_KEY));

    /* Update LCD Display */
    LCD_DisplayStringLine(Line5, (uint8_t*)MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line6, (uint8_t*)MEASSAGE_EMPTY);

    /* Write operation */
    CPAL_I2C_Write(&MASTERSTRUCTURE);

    /* Wait until communication finishes */
    while ((MASTERSTRUCTURE.CPAL_State != CPAL_STATE_READY) && (MASTERSTRUCTURE.CPAL_State != CPAL_STATE_ERROR));

    if (TransferStatus == PASSED)
    {
      /* Update LCD Display */
      LCD_SetBackColor(Red);
      LCD_SetTextColor(White);
      LCD_DisplayStringLine(Line8, (uint8_t*)MESSAGE6);
    }
    else
    {
      TransferStatus = PASSED;
    }

    Delay(1000);
  }
#endif /* I2C_MASTER */

  /* if STM32 device is set as Slave */  
#ifdef I2C_SLAVE

  /* GPIOA Periph clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  /* Output System Clock on MCO pin (PA.08) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

#if defined(STM32F303xC)
  RCC_MCOConfig(RCC_MCOSource_SYSCLK);
#else /* STM32F334x8 || STM32F302x8 || STM32F303xE */
  RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCOPrescaler_1);
#endif /* STM32F303xC */

  /* Deinitialize I2Cx Device */ 
  CPAL_I2C_DeInit(&SLAVESTRUCTURE); 

  /* Initialize CPAL I2C structure parameters values */
  CPAL_I2C_StructInit(&SLAVESTRUCTURE);
  SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP;
  
#ifdef CPAL_I2C_DMA_PROGMODEL
  SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
 #error "Please select one of the programming model (in main.h)"
#endif

  /* Configure Own address 1 */
  SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS;

  /* Set I2C Speed */
  SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING;

  /* Select Slave Mode */ 
  SLAVESTRUCTURE.CPAL_Mode = CPAL_MODE_SLAVE; 

  /* Initialize I2Cx Device*/
  CPAL_I2C_Init(&SLAVESTRUCTURE);

  /* Infinite loop */
  while(1)
  {
    /* Reset BufferRX value */
    Reset_bBuffer(BufferRX, BufferSize);

    /* Initialize Transfer parameters */
    SLAVESTRUCTURE.pCPAL_TransferRx = &sRxStructure;
    sRxStructure.wNumData = BufferSize;
    sRxStructure.pbBuffer = (uint8_t*)BufferRX;

    /* Update LCD Display */
    LCD_SetBackColor(White);
    LCD_SetTextColor(Blue);
    LCD_DisplayStringLine(Line8, (uint8_t*)MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line9, (uint8_t*)MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line5, (uint8_t*)MESSAGE7);

    Delay(1000);

    /* Update LCD Display */
    LCD_DisplayStringLine(Line5, (uint8_t*)MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line6, (uint8_t*)MESSAGE8);
    
    /* Read operation */
    CPAL_I2C_Read(&SLAVESTRUCTURE);  

    /* Enter Stop Mode and wait for interrupt to wake up */
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

    /* Wait until communication finishes */
    while ((SLAVESTRUCTURE.CPAL_State != CPAL_STATE_READY) && (SLAVESTRUCTURE.CPAL_State != CPAL_STATE_ERROR));

    /* Configure SystemClock*/
    RestoreConfiguration();

    /* Configure and enable the systick timer to generate an interrupt each 1 ms */
    SysTick_Config((SystemCoreClock / 1000));

    /* Update LCD Display */
    LCD_DisplayStringLine(Line6, (uint8_t*)MEASSAGE_EMPTY);
    LCD_SetBackColor(Red);
    LCD_SetTextColor(White);
    LCD_DisplayStringLine(Line8, (uint8_t*)MESSAGE9);

    /* If are received correctly */
    if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED )
    {
      /* Update LCD Display */
      LCD_DisplayStringLine(Line9, (uint8_t*)MESSAGE6);
    }
    else
    {
      /* Update LCD Display */
      LCD_DisplayStringLine(Line9, (uint8_t*)MESSAGE10);
    }

    Delay(1500);
  }
#endif /* I2C_SLAVE */
}