Esempio n. 1
0
int stm32_i2c_read(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char *data)
{
    if (!length)
        return 0;
  /* Disable all options */
  MPU9150_DevStructure.wCPAL_Options = 0;

  /* point to CPAL_TransferTypeDef structure */
  MPU9150_DevStructure.pCPAL_TransferRx = &MPU9150_RXTransfer;
  
  /* Configure transfer parameters */  
  MPU9150_DevStructure.pCPAL_TransferRx->wNumData = (uint32_t)length;
  MPU9150_DevStructure.pCPAL_TransferRx->pbBuffer = data ;
  MPU9150_DevStructure.pCPAL_TransferRx->wAddr1   = (uint32_t)slave_addr;
  MPU9150_DevStructure.pCPAL_TransferRx->wAddr2   = (uint32_t)reg_addr;
  
  /* Read Operation */
  if(CPAL_I2C_Read(&MPU9150_DevStructure) == CPAL_PASS)
  {
    while ((MPU9150_DevStructure.CPAL_State != CPAL_STATE_READY) && (MPU9150_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
    { }
		
    if (MPU9150_DevStructure.CPAL_State == CPAL_STATE_ERROR)
    {
      return -1;
    }
  } else
      return -1;
  
      return 0;
}
Esempio n. 2
0
uint8_t mBusReadBurstNoAdd(uint8_t slaveAddr, uint8_t length, uint8_t *data, uint8_t i2cNum)
{
  mBusTypeDef* mBusCurrent = getmBusPtr(i2cNum);
  CPAL_InitTypeDef* mBusStruct = mBusCurrent->CPAL_InitStruct;
  mBusStruct->wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  mBusStruct->pCPAL_TransferRx = &(mBusCurrent->mBusRx); 
  mBusStruct->pCPAL_TransferRx->wNumData = length;
  mBusStruct->pCPAL_TransferRx->pbBuffer = mBusCurrent->bufferBurstRd;
  mBusStruct->pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;

  if(CPAL_I2C_Read(mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct->CPAL_State != CPAL_STATE_READY) && (mBusStruct->CPAL_State != CPAL_STATE_ERROR)){}
    if(mBusStruct->CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct->CPAL_State = CPAL_STATE_READY;
      mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
      return ERROR;
    }
    mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    for(uint8_t i=0;i<length;i++)
    {
      data[i] = mBusCurrent->bufferBurstRd[i]; 
    }
    return SUCCESS;
  }
  else
  {
    mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return ERROR;
  }
}
/**
  * @brief  Reads a buffer of 2 bytes from the device registers.
  * @param  DeviceAddr: The address of the device, could be : IOE_1_ADDR.
  * @param  RegisterAddr: The target register address (between 00x and 0x24)
  * @retval A pointer to the buffer containing the two returned bytes (in halfword).  
  */
uint16_t I2C_ReadDataBuffer(uint8_t DeviceAddr, uint32_t RegisterAddr)
{  
  IOE_Buffer[0] = 0;
  IOE_Buffer[1] = 0;
  
  /* Disable all options */
  IOE_DevStructure.wCPAL_Options  = 0;
  
  /* point to CPAL_TransferTypeDef structure */
  IOE_DevStructure.pCPAL_TransferRx = &IOE_RXTransfer;
  
  /* Configure transfer parameters */  
  IOE_DevStructure.pCPAL_TransferRx->wNumData = 2;
  IOE_DevStructure.pCPAL_TransferRx->pbBuffer = IOE_Buffer ;
  IOE_DevStructure.pCPAL_TransferRx->wAddr1   = (uint32_t)DeviceAddr;
  IOE_DevStructure.pCPAL_TransferRx->wAddr2   = (uint32_t)RegisterAddr;
  
  /* read Operation */
  if (CPAL_I2C_Read(&IOE_DevStructure)== CPAL_PASS)
  {
    while ((IOE_DevStructure.CPAL_State != CPAL_STATE_READY) && (IOE_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
    { }
  }
  
  /* return buffer value */
  return (uint16_t)(IOE_Buffer[1] + (IOE_Buffer[0]<<8));
}
Esempio n. 4
0
uint8_t mBusReadNoAdd(uint8_t slaveAddr)
{
  bufferRd[0] = 0;
  mBusStruct.wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  mBusStruct.pCPAL_TransferRx = &mBusRx; 
  mBusStruct.pCPAL_TransferRx->wNumData = 1;
  mBusStruct.pCPAL_TransferRx->pbBuffer = bufferRd ;
  mBusStruct.pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;

  if(CPAL_I2C_Read(&mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct.CPAL_State != CPAL_STATE_READY) && (mBusStruct.CPAL_State != CPAL_STATE_ERROR)){}
    if(mBusStruct.CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct.CPAL_State = CPAL_STATE_READY;
      mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
      return ERROR;
    }
    mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return bufferRd[0];
  }
  else
  {
    mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return ERROR;
  } 
}
Esempio n. 5
0
uint8_t mBusRead(uint8_t slaveAddr, uint8_t regAddr, uint8_t i2cNum)
{
  mBusTypeDef* mBusCurrent = getmBusPtr(i2cNum);
  CPAL_InitTypeDef* mBusStruct = mBusCurrent->CPAL_InitStruct;
	mBusCurrent->bufferRd[0] = 0;
	mBusStruct->pCPAL_TransferRx = &mBusCurrent->mBusRx; 
  mBusStruct->pCPAL_TransferRx->wNumData = 1;
 	mBusStruct->pCPAL_TransferRx->pbBuffer = mBusCurrent->bufferRd;
  mBusStruct->pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBusStruct->pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;

  if(CPAL_I2C_Read(mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct->CPAL_State != CPAL_STATE_READY) && (mBusStruct->CPAL_State != CPAL_STATE_ERROR)){}
	  if(mBusStruct->CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct->CPAL_State = CPAL_STATE_READY;
      return ERROR;
    }
    return mBusCurrent->bufferRd[0];
  }
  else
  {
    return ERROR;
  }	
}
Esempio n. 6
0
uint8_t mBusReadNoAdd(uint8_t slaveAddr, uint8_t i2cNum)
{
  mBusTypeDef* mBusCurrent = getmBusPtr(i2cNum);
  CPAL_InitTypeDef* mBusStruct = mBusCurrent->CPAL_InitStruct;
  mBusCurrent->bufferRd[0] = 0;
  mBusStruct->wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  mBusStruct->pCPAL_TransferRx = &(mBusCurrent->mBusRx); 
  mBusStruct->pCPAL_TransferRx->wNumData = 1;
  mBusStruct->pCPAL_TransferRx->pbBuffer = mBusCurrent->bufferRd;
  mBusStruct->pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;

  if(CPAL_I2C_Read(mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct->CPAL_State != CPAL_STATE_READY) && (mBusStruct->CPAL_State != CPAL_STATE_ERROR)){}
    if(mBusStruct->CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct->CPAL_State = CPAL_STATE_READY;
      mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
      return ERROR;
    }
    mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return mBusCurrent->bufferRd[0];
  }
  else
  {
    mBusStruct->wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return ERROR;
  } 
}
Esempio n. 7
0
void I2C_Lib_MasterRW(I2C_Lib_Op_Type op,uint8_t slave_addr,uint16_t length,uint8_t* data)
{
    static CPAL_TransferTypeDef CPAL_Transfer; //Must be static because I2C transfer is async

    I2C_Lib_WaitForRWDone();
    
    CPAL_Transfer.wNumData = length;
    CPAL_Transfer.pbBuffer = data;
    CPAL_Transfer.wAddr1 = (uint32_t)slave_addr<<1; //device address is high 7-bit
    // CPAL_Transfer.wAddr2 = (uint32_t)reg_addr;

    I2C_HOST_DEV.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR;

    if(op == I2C_OP_Write){
        I2C_HOST_DEV.pCPAL_TransferTx = &CPAL_Transfer;
        if(CPAL_I2C_Write(&I2C_HOST_DEV) != CPAL_PASS){
            ERR_MSG("CPAL_I2C_Write Failed");
        }
    }
    else if(op == I2C_OP_Read){
        I2C_HOST_DEV.pCPAL_TransferRx = &CPAL_Transfer;
        if(CPAL_I2C_Read(&I2C_HOST_DEV) != CPAL_PASS){
            ERR_MSG("CPAL_I2C_Read Failed");
        }
    }

}
Esempio n. 8
0
uint8_t mBusMasterReadBurstStart(uint8_t slaveAddr, uint16_t regAddr, uint8_t length, uint8_t i2cNum)
{
  mBusTypeDef* mBus = getmBusPtr(i2cNum);

  if(mBus->CPAL_InitStruct->CPAL_State != CPAL_STATE_READY) {
    WarnReport(ERROR_MBUS_MASTER_READ_BURST_START, "CPAL Not Ready, Mode=%u,State=%u,Error=%u",
      mBus->CPAL_InitStruct->CPAL_Mode,
      mBus->CPAL_InitStruct->CPAL_State,
      mBus->CPAL_InitStruct->wCPAL_DevError);
    //return ERROR;
    mBus->CPAL_InitStruct->CPAL_State = CPAL_STATE_READY;
  }

  mBus->CPAL_InitStruct->pCPAL_TransferRx           = &(mBus->mBusRx); 
  mBus->CPAL_InitStruct->pCPAL_TransferRx->wNumData = length;
  mBus->CPAL_InitStruct->pCPAL_TransferRx->pbBuffer = mBus->bufferBurstRd;
  mBus->CPAL_InitStruct->pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBus->CPAL_InitStruct->pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;
  mBus->CPAL_InitStruct->wCPAL_Options              |= CPAL_OPT_16BIT_REG;

  if(CPAL_I2C_Read(mBus->CPAL_InitStruct) == CPAL_PASS) {
    mBus->mBusReadBurstStartFlag=1;
    return SUCCESS;
  }
  else {
    WarnReport(ERROR_MBUS_MASTER_READ_BURST_START, "CPAL_I2C_Read failed");
    return ERROR;
  }
}
/**
  * @brief  Read the specified register from the LM75.
  * @param  RegName: specifies the LM75 register to be read.
  *              This member can be one of the following values:  
  *                  - LM75_REG_TEMP: temperature register
  *                  - LM75_REG_TOS: Over-limit temperature register
  *                  - LM75_REG_THYS: Hysteresis temperature register
  * @retval LM75 register value.
  */
uint16_t LM75_ReadReg(uint8_t RegName)
{   
  uint16_t tmp = 0;
  
  LM75_Buffer[0] = 0;
  LM75_Buffer[1] = 0;
  
  /* Disable all options */
  LM75_DevStructure.wCPAL_Options = 0;

  /* point to CPAL_TransferTypeDef structure */
  LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
  
  /* Configure transfer parameters */  
  LM75_DevStructure.pCPAL_TransferRx->wNumData = 2;
  LM75_DevStructure.pCPAL_TransferRx->pbBuffer = LM75_Buffer ;
  LM75_DevStructure.pCPAL_TransferRx->wAddr1   = (uint32_t)LM75_ADDR;
  LM75_DevStructure.pCPAL_TransferRx->wAddr2   = (uint32_t)RegName;
  
  /* Read Operation */
  if(CPAL_I2C_Read(&LM75_DevStructure) == CPAL_PASS)
  {
    while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
    { }
  }
  
  /* Store LM75_I2C received data */
  tmp = (uint16_t)(LM75_Buffer[0] << 8);
  tmp |= LM75_Buffer[1];
  
  /* return a Reg value */
  return (uint16_t)tmp;  
}
Esempio n. 10
0
uint8_t mBusReadBurstNoAdd(uint8_t slaveAddr, uint8_t length, uint8_t *data)
{
  mBusStruct.wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  mBusStruct.pCPAL_TransferRx = &mBusRx; 
  mBusStruct.pCPAL_TransferRx->wNumData = length;
  mBusStruct.pCPAL_TransferRx->pbBuffer = bufferBurstRd ;
  mBusStruct.pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;

  if(CPAL_I2C_Read(&mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct.CPAL_State != CPAL_STATE_READY) && (mBusStruct.CPAL_State != CPAL_STATE_ERROR)){}
    if(mBusStruct.CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct.CPAL_State = CPAL_STATE_READY;
      mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
      return ERROR;
    }
    mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    for(uint8_t i=0;i<length;i++)
    {
      data[i] = bufferBurstRd[i]; 
    }
    return SUCCESS;
  }
  else
  {
    mBusStruct.wCPAL_Options &= ~CPAL_OPT_NO_MEM_ADDR;
    return ERROR;
  }
}
/**
  * @brief  Reads a block of data from the EEPROM.
  * @param  sEEInitStruct : Pointer to sEE Device structure
  * @param  pBuffer : pointer to the buffer that receives the data read from 
  *         the EEPROM.
  * @param  ReadAddr : EEPROM's internal address to read from.
  * @param  NumByteToRead : pointer to the variable holding number of bytes to 
  *         read from the EEPROM. 
  * 
  *        @note The variable pointed by NumByteToRead is reset to 0 when all the 
  *              data are read from the EEPROM. Application should monitor this 
  *              variable in order know when the transfer is complete.
  * 
  * @note When number of data to be read is higher than 1, this function just 
  *       configure the communication and enable the DMA channel to transfer data.
  *       Meanwhile, the user application may perform other tasks.
  *       When number of data to be read is 1, then the DMA is not used.
  * 
  * @retval None
  */
uint32_t sEE_ReadBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
                        uint16_t ReadAddr, uint32_t NumByteToRead)
{  
  if (sEEInitStruct->sEEState == sEE_STATE_IDLE)
  {
    sEEInitStruct->sEEState = sEE_STATE_READING;
    
    sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;

 /* Enable 16Bit memory register option on CPAL */
  if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_16BIT_REG)
  {
    sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_16BIT_REG;
  }
  
   /* Enable no memory addressing mode option on CPAL */
  if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_NO_MEM_ADDR)
  {
    sEEInitStruct->sEE_CPALStructure->wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  }
    
    sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx   = sEE_RXTransfer[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]; 
    
    sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wNumData = (uint32_t)(NumByteToRead);
    sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->pbBuffer = pBuffer;
    sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr1   = (uint32_t)((uint8_t)sEEInitStruct->sEEAddress);
    sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr2   = (uint32_t)((uint16_t)ReadAddr);
    
    return CPAL_I2C_Read(sEEInitStruct->sEE_CPALStructure);  
  }
  else
  {
    return CPAL_FAIL;
  }
}
Esempio n. 12
0
uint8_t mBusReadBurst(uint8_t slaveAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
{
  mBusStruct.pCPAL_TransferRx = &mBusRx; 
  mBusStruct.pCPAL_TransferRx->wNumData = length;
  mBusStruct.pCPAL_TransferRx->pbBuffer = bufferBurstRd ;
  mBusStruct.pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBusStruct.pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;

  if(CPAL_I2C_Read(&mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct.CPAL_State != CPAL_STATE_READY) && (mBusStruct.CPAL_State != CPAL_STATE_ERROR)){}
    if(mBusStruct.CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct.CPAL_State = CPAL_STATE_READY;
      return ERROR;
    }
    for(uint8_t i=0;i<length;i++)
    {
      data[i] = bufferBurstRd[i]; 
    }
    return SUCCESS;
  }
  else
  {
    return ERROR;
  }
}
Esempio n. 13
0
void EXTI9_5_IRQHandler(void)
{
    if (EXTI_GetITStatus(EXTI_Line5) != RESET)
    {
        EXTI_ClearITPendingBit(EXTI_Line5);

        buff.pbBuffer = i2c_buff;
        buff.wAddr1 = PRESSURE_SLAVE_ADDRESS << 1;
        buff.wAddr2 = PRESSURE_REG_TEMP_LOW;
        buff.wNumData = sizeof(pressure_t);
        I2C1_DevStructure.pCPAL_TransferRx = &buff;
        CPAL_I2C_Read(&I2C1_DevStructure);
    }
}
Esempio n. 14
0
uint8_t mBusReadBurstStartNB(uint8_t slaveAddr, uint8_t regAddr, uint8_t length)
{
	mBusStruct.pCPAL_TransferRx = &mBusRx; 
  mBusStruct.pCPAL_TransferRx->wNumData = length;
 	mBusStruct.pCPAL_TransferRx->pbBuffer = bufferBurstRd ;
  mBusStruct.pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBusStruct.pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;

  	if(CPAL_I2C_Read(&mBusStruct) == CPAL_PASS)
  	{
      mBusReadBurstStartFlag=1;
  		return SUCCESS;
  	}
  	else 
  	{
  		return ERROR;
  	}
}
Esempio n. 15
0
uint8_t mBusReadBurstStartNB(uint8_t slaveAddr, uint8_t regAddr, uint8_t length, uint8_t i2cNum)
{
  mBusTypeDef* mBusCurrent = getmBusPtr(i2cNum);
  CPAL_InitTypeDef* mBusStruct = mBusCurrent->CPAL_InitStruct;
  if(mBusStruct->CPAL_State != CPAL_STATE_READY){return ERROR;}
	mBusStruct->pCPAL_TransferRx = &(mBusCurrent->mBusRx); 
  mBusStruct->pCPAL_TransferRx->wNumData = length;
 	mBusStruct->pCPAL_TransferRx->pbBuffer = mBusCurrent->bufferBurstRd;
  mBusStruct->pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBusStruct->pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;

  	if(CPAL_I2C_Read(mBusStruct) == CPAL_PASS)
  	{
      mBusCurrent->mBusReadBurstStartFlag=1;
  		return SUCCESS;
  	}
  	else 
  	{
  		return ERROR;
  	}
}
Esempio n. 16
0
uint8_t mBusRead(uint8_t slaveAddr, uint8_t regAddr)
{
	bufferRd[0] = 0;
	mBusStruct.pCPAL_TransferRx = &mBusRx; 
  mBusStruct.pCPAL_TransferRx->wNumData = 1;
 	mBusStruct.pCPAL_TransferRx->pbBuffer = bufferRd ;
  mBusStruct.pCPAL_TransferRx->wAddr1   = (uint32_t)slaveAddr;
  mBusStruct.pCPAL_TransferRx->wAddr2   = (uint32_t)regAddr;

  if(CPAL_I2C_Read(&mBusStruct) == CPAL_PASS)
  {
    while((mBusStruct.CPAL_State != CPAL_STATE_READY) && (mBusStruct.CPAL_State != CPAL_STATE_ERROR)){}
	  if(mBusStruct.CPAL_State == CPAL_STATE_ERROR)
    {
      mBusStruct.CPAL_State = CPAL_STATE_READY;
      return ERROR;
    }
    return bufferRd[0];
  }
  else
  {
    return ERROR;
  }	
}
Esempio n. 17
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_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
  */
    
  /* Configure Clocks */
  RCC_Config();
  
  /* Initialize LEDs, Key Button and LCD available on
  STM320518-EVAL board *****************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* Initialize the LCD */
  STM320518_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, MESSAGE1);
  LCD_DisplayStringLine(Line1, 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);
  
#ifdef CPAL_I2C_DMA_PROGMODEL
  MASTERSTRUCTURE.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT;
  MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  MASTERSTRUCTURE.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR;
  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, MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line5, MESSAGE4);
    LCD_DisplayStringLine(Line6, MESSAGE5);
    
    /* wait until Key button is pushed */
    while(STM_EVAL_PBGetState(BUTTON_KEY));
    
    /* Update LCD Display */
    LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line6, 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, 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);
  
  RCC_MCOConfig(RCC_MCOSource_SYSCLK);
  
  /* Deinitialize I2Cx Device */ 
  CPAL_I2C_DeInit(&SLAVESTRUCTURE); 
  
  /* Initialize CPAL I2C structure parameters values */
  CPAL_I2C_StructInit(&SLAVESTRUCTURE);
  
#ifdef CPAL_I2C_DMA_PROGMODEL
  SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT;
  SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  SLAVESTRUCTURE.wCPAL_Options =  CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP;
  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, (uint16_t)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, MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line5, MESSAGE7);
    
    Delay(1000);
    
    /* Update LCD Display */
    LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY);
    LCD_DisplayStringLine(Line6, 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, MEASSAGE_EMPTY);    
    LCD_SetBackColor(Red);
    LCD_SetTextColor(White);     
    LCD_DisplayStringLine(Line8, MESSAGE9);
    
    /* If are received correctly */
    if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED )
    {          
      /* Update LCD Display */
      LCD_DisplayStringLine(Line9, MESSAGE6);      
    }
    else
    {          
      /* Update LCD Display */
      LCD_DisplayStringLine(Line9, MESSAGE10);
    }
    
    Delay(1500);
  }  
#endif /* I2C_SLAVE */
}
Esempio n. 18
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_stm32xxx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32xxx.c file
  */
  
  /* Initialize LEDs, Key Button, LCD and COM port(USART) available on
  STM3210X-EVAL board ******************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
    
  /* Initialize TIM6 */
  TIM6_Config();
  
  /* Initialize the LCD */
#ifdef USE_STM322xG_EVAL   
  STM322xG_LCD_Init();
#elif defined USE_STM324xG_EVAL   
  STM324xG_LCD_Init();
#elif defined USE_STM3210C_EVAL   
  STM3210C_LCD_Init();
#elif defined USE_STM32100E_EVAL
  STM32100E_LCD_Init();  
#elif defined USE_STM32L152_EVAL
  STM32L152_LCD_Init();
#elif defined USE_STM32L152D_EVAL
  STM32L152D_LCD_Init();
#endif
  
  /* Display message on STM3210X-EVAL 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, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line5, MESSAGE3);
  
  /* Configure the Push buttons in interrupt mode *****************************/
#if defined (USE_STM32100E_EVAL) || defined(USE_STM3210C_EVAL)  || defined(USE_STM322xG_EVAL ) || defined (USE_STM324xG_EVAL)
  STM_EVAL_PBInit(BUTTON_KEY, Mode_EXTI);
  STM_EVAL_PBInit(BUTTON_TAMPER, Mode_EXTI);
#elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL)
  STM_EVAL_PBInit(BUTTON_LEFT, Mode_EXTI);
  STM_EVAL_PBInit(BUTTON_RIGHT, Mode_EXTI);
#endif /* USE_STM32100E_EVAL || USE_STM3210C_EVAL || USE_STM322xG_EVAL || USE_STM324xG_EVAL */
  
  /* Start CPAL communication configuration ***********************************/
  /* Initialize local Reception structures */
  sRxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sRxStructure.pbBuffer = tRxBuffer;        /* Common Rx buffer for all received data */
  sRxStructure.wAddr1 = OWN_ADDRESS;        /* The own board address */
  sRxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Initialize local Transmission structures */
  sTxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sTxStructure.pbBuffer = (uint8_t*)tStateSignal;     /* Common Rx buffer for all received data */
  sTxStructure.wAddr1 = OWN_ADDRESS;        /* The own board address */
  sTxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Configure the device structure */
  CPAL_I2C_StructInit(&I2C_DevStructure);      /* Set all fields to default values */
  I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
#ifdef CPAL_I2C_DMA_PROGMODEL
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
 #error "Please select one of the programming model (in main.h)"
#endif
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_ClockSpeed = I2C_SPEED;
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWN_ADDRESS;
  I2C_DevStructure.pCPAL_TransferRx = &sRxStructure;
  I2C_DevStructure.pCPAL_TransferTx = &sTxStructure;
  
  /* Initialize CPAL device with the selected parameters */
  CPAL_I2C_Init(&I2C_DevStructure);    
  
  /* Infinite loop */
  while (1)
  {
    /* Write operations ------------------------------------------------------*/
    /* Check if any action has been triggered by push buttons */
    if ((ActionState != ACTION_PENDING) && (ActionState != ACTION_NONE))
    {
      /* Check if the current CPAL device state allows write operation */
      if (((DeviceMode == SLAVE) && (LastMode == SLAVE))||\
         (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) ||\
           (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && (DeviceMode == MASTER)))
      {  
        if (LastMode == SLAVE)
        {         
          /* Set the LCD Back Color */
          LCD_SetBackColor(Red);
          /* Set the LCD Text Color */
          LCD_SetTextColor(White);
          LCD_DisplayStringLine(Line3, (uint8_t*)" MASTER MODE ACTIVE ");
          /* Set the LCD Back Color */
          LCD_SetBackColor(White);
          /* Set the LCD Text Color */
          LCD_SetTextColor(Blue);
          
          /* Disable CPAL_OPT_I2C_NACK_ADD option when switch to Master mode */
          I2C_DevStructure.wCPAL_Options &= (~CPAL_OPT_I2C_NACK_ADD);
        }
        
        LastMode = MASTER;        
        
        /* Initialize local Reception structures */
        sRxStructure.wNumData = BufferSize;
        
        /* Initialize local Transmission structures */
        sTxStructure.wNumData = BufferSize;
        
        switch (ActionState)
        {
          
        case BUTTON_KEY: 
          TransmitMode = STATE_ON;
          sTxStructure.pbBuffer = (uint8_t*)tSignal; 
          Divider = 2;
          break;
          
        case BUTTON_TAMPER:
          TransmitMode = STATE_OFF;          
          sRxStructure.pbBuffer = tRxBuffer;        
          Divider = 4;
          break;
          
        case ACTION_PERIODIC:
          if(TransmitMode == STATE_ON)
          {
            sTxStructure.pbBuffer = (uint8_t*)tStateSignal; 
          }
          break;    
          
        default:
          break;            
        } 
        
        /* Configure the device mode to master */
        I2C_DevStructure.CPAL_Mode = CPAL_MODE_MASTER;
        /* Force the CPAL state to ready (in case a read operation has been initiated) */
        I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
        
        /* Prevent other actions to be performed while the current is not finished */
        ActionState = ACTION_PENDING;
        DeviceMode = MASTER;
        
        /* Configure a Timer to generate periodic interrupt: used to send state signal */
        TIM7_Config(PeriodicValue/Divider);   
        
        if(TransmitMode == STATE_ON)
        {
          /* Start writing data in master mode */
          if (CPAL_I2C_Write(&I2C_DevStructure) == CPAL_PASS)
          {
          }
        }
        else
        {
          /* Start reading data in master mode */
          if (CPAL_I2C_Read(&I2C_DevStructure) == CPAL_PASS)
          {
          }
        }
        
      }      
    }
    
    
    /* Read Operations -------------------------------------------------------*/
    if (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) || \
         (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && \
         (DeviceMode == SLAVE))
    {                  
      /* Reconfigure device for slave receiver mode */
      I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
      I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
      
      if (LastMode == SLAVE)
      {        
        /* Set the LCD Back Color */
        LCD_SetBackColor(Red);
        /* Set the LCD Text Color */
        LCD_SetTextColor(White);
        LCD_DisplayStringLine(Line3, (uint8_t*)"  SLAVE MODE ACTIVE ");
        /* Set the LCD Back Color */
        LCD_SetBackColor(White);
        /* Set the LCD Text Color */
        LCD_SetTextColor(Blue);
      }
      
      /* Start waiting for data to be received in slave mode */
      if (CPAL_I2C_Listen(&I2C_DevStructure) == CPAL_PASS)
      {
        LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); 
      }
    }   
  }
}
Esempio n. 19
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_stm32f0xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f0xx.c file
  */
  
  /* Initialize LEDs and LCD available on STM320518-EVAL board ****************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
    
  /* Initialize TIM6 */
  TIM6_Config();
  
  /* Initialize the LCD */
  STM320518_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, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line3, MESSAGE3);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  
  /* Configure the Push buttons in interrupt mode *****************************/
  STM_EVAL_PBInit(BUTTON_KEY, Mode_EXTI);
  STM_EVAL_PBInit(BUTTON_TAMPER, Mode_EXTI);
  
  /* Start CPAL communication configuration ***********************************/
  /* Initialize local Reception structures */
  sRxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sRxStructure.pbBuffer = tRxBuffer;        /* Common Rx buffer for all received data */
  sRxStructure.wAddr1 = 0;                  /* Not needed */
  sRxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Initialize local Transmission structures */
  sTxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sTxStructure.pbBuffer = (uint8_t*)tStateSignal;     /* Common Rx buffer for all received data */
  sTxStructure.wAddr1 = OWN_ADDRESS;        /* The own board address */
  sTxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Set SYSCLK as I2C clock source */
  RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);
  
  /* Configure the device structure */
  CPAL_I2C_StructInit(&I2C_DevStructure);      /* Set all fields to default values */
  I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
#ifdef CPAL_I2C_DMA_PROGMODEL
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT | CPAL_OPT_DMARX_TCIT;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
 #error "Please select one of the programming model (in stm32f0xx_i2c_cpal_conf.h)"
#endif
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_Timing = I2C_TIMING;
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWN_ADDRESS;
  I2C_DevStructure.pCPAL_TransferRx = &sRxStructure;
  I2C_DevStructure.pCPAL_TransferTx = &sTxStructure;
  
  /* Initialize CPAL device with the selected parameters */
  CPAL_I2C_Init(&I2C_DevStructure);    
  
  /* Infinite loop */
  while (1)
  {
    /* Write operations ------------------------------------------------------*/
    /* Check if any action has been triggered by push buttons */
    if ((ActionState != ACTION_PENDING) && (ActionState != ACTION_NONE))
    {
      /* Check if the current CPAL device state allows write operation */
      if ((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) || \
        (I2C_DevStructure.CPAL_State == CPAL_STATE_BUSY_RX) ||\
          (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED))
      {        
        /* Initialize local Transmission structures */
        sTxStructure.wNumData = BufferSize;   /* Maximum Number of data to be received */
        sTxStructure.wAddr1 = OWN_ADDRESS;    /* The own board address */
        sTxStructure.wAddr2 = 0;              /* Not needed */        
        
        switch (ActionState)
        {
          
        case BUTTON_KEY: 
          sTxStructure.pbBuffer = (uint8_t*)tSignal1; 
          Divider = 1;
          break;
          
        case BUTTON_TAMPER:
          sTxStructure.pbBuffer = (uint8_t*)tSignal2; 
          Divider = 2;
          break;
          
        case ACTION_PERIODIC:
          sTxStructure.pbBuffer = (uint8_t*)tStateSignal; 
          break;    
          
        default:
          sTxStructure.pbBuffer = (uint8_t*)tSignal1; 
          break;            
        } 
        
        /* Configure the device mode to master */
        I2C_DevStructure.CPAL_Mode = CPAL_MODE_MASTER;
        /* Force the CPAL state to ready (in case a read operation has been initiated) */
        I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
                
        /* Prevent other actions to be performed while the current is not finished */
        ActionState = ACTION_PENDING;
        TransmitMode = STATE_ON;
        
        /* Configure a Timer to generate periodic interrupt: used to send state signal */
        TIM17_Config(PeriodicValue/Divider);   
        
        /* Start writing data in master mode */
        if (CPAL_I2C_Write(&I2C_DevStructure) == CPAL_PASS)
        {
         }
      }      
    }
    
    
    /* Read Operations -------------------------------------------------------*/
    if (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) || \
      (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && \
        (TransmitMode == STATE_OFF))
    {                  
      /* Initialize local Reception structures */
      sRxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
      sRxStructure.pbBuffer = tRxBuffer;        /* Common Rx buffer for all received data */
      
      /* Reconfigure device for slave receiver mode */
      I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
      I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
      
      /* Start waiting for data to be received in slave mode */
      if (CPAL_I2C_Read(&I2C_DevStructure) == CPAL_PASS)
      {
        LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); 
      }
    }   
  }
}
Esempio n. 20
0
int main()
{
    GPIO_InitTypeDef GPIO_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;




    LED_Init();
    LED_R_ON();


    CPAL_I2C_StructInit(&I2C1_DevStructure);
    I2C1_DevStructure.CPAL_Dev = CPAL_I2C1;
    I2C1_DevStructure.pCPAL_I2C_Struct->I2C_ClockSpeed = 400000;
    I2C1_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
    I2C1_DevStructure.wCPAL_Options = 0;

    CPAL_I2C_Init(&I2C1_DevStructure);




    // Interrupt input(PB5) configuration
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    EXTI_InitStructure.EXTI_Line = EXTI_Line5;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);



    LLIO_Init(115200);
    printf("\r\nmyPressure I2C example\r\n");




    // myPressure의 WHO_AM_I 레지스터 값을 읽어 출력한다.
    // read 결과값은 등록된 user callback을 통해 받아온다.
    buff.pbBuffer = i2c_buff;
    buff.wAddr1 = PRESSURE_SLAVE_ADDRESS << 1;
    buff.wAddr2 = PRESSURE_REG_WHO_AM_I;
    buff.wNumData = 1;

    I2C1_DevStructure.pCPAL_TransferRx = &buff;
    printf("\r\n\r\nread : %d\r\n", CPAL_I2C_Read(&I2C1_DevStructure));


    while(1)
    {
        __WFI();    // 인터럽트가 발생할 때 까지 이곳에서 대기
    }

}