Esempio n. 1
0
/**
 * @brief  Initializes the EEPROM
 * @param  None
 * @retval None
 */
ErrorStatus I2C_EEPROM_Init()
{
  /* Make sure we only initialize it once */
  if (!prvInitialized)
  {
    /* I2C */
    I2C3_Init();

    /* EEPROM WP configuration */
    I2C_EEPROM_WP_GPIO_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.Pin        = I2C_EEPROM_WP_PIN;
    GPIO_InitStructure.Mode       = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Pull       = GPIO_NOPULL;
    GPIO_InitStructure.Speed      = GPIO_SPEED_LOW;
    HAL_GPIO_Init(I2C_EEPROM_WP_PORT, &GPIO_InitStructure);
    I2C_EEPROM_DisableWriteProtection();

    /* Mutex semaphore for mutual exclusion to the EEPROM device */
    xSemaphore = xSemaphoreCreateMutex();

    /* Initialize xNextWriteTime - this only needs to be done once. */
    xNextWriteTime = xTaskGetTickCount();

    prvInitialized = true;

    return SUCCESS;
  }
  else
    return ERROR;
}
Esempio n. 2
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART to 115200-8n1 for print message */
    UART_Open(UART0, 115200);

    /*
        This sample code sets I2C bus clock to 100kHz. Then, Master accesses Slave with Byte Write
        and Byte Read operations, and check if the read data is equal to the programmed data.
    */

    printf("+-------------------------------------------------------+\n");
    printf("|       I2C Driver Sample Code(Master) for access Slave |\n");
    printf("+-------------------------------------------------------+\n");

    /* Init I2C3 */
    I2C3_Init();

    /* Access Slave with no address mask */
    printf("\n");
    printf(" == No Mask Address ==\n");
    Read_Write_SLAVE(0x15);
    Read_Write_SLAVE(0x35);
    Read_Write_SLAVE(0x55);
    Read_Write_SLAVE(0x75);
    printf("SLAVE Address test OK.\n");

    /* Access Slave with address mask */
    printf("\n");
    printf(" == Mask Address ==\n");
    Read_Write_SLAVE(0x15 & ~0x01);
    Read_Write_SLAVE(0x35 & ~0x04);
    Read_Write_SLAVE(0x55 & ~0x01);
    Read_Write_SLAVE(0x75 & ~0x04);
    printf("SLAVE Address Mask test OK.\n");

    while(1);
}