Exemplo n.º 1
0
/**
* @brief  Wait polling the SPI until the internal WIP flag is RESET.
*         The flag is SET when a write operation is running.
* @param  None
* @retval None
*/
void EepromWaitEndWriteOperation(void)
{
  uint8_t cmd = EEPROM_CMD_RDSR;
  uint8_t dummy = 0xFF;
  uint8_t status;
  //  SPI_ENTER_CRITICAL();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow();
  
  //  for(volatile uint16_t i=0;i<CS_TO_SCLK_DELAY;i++);
  
  /* Send command */
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  SPI_SendData(s_EepromSpiPort, cmd);
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
  SPI_ReceiveData(s_EepromSpiPort);
  
  /* Polling on status register */
  do{
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, dummy);
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    status = SPI_ReceiveData(s_EepromSpiPort);
  }while(status&EEPROM_STATUS_WIP);
  
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
  
  //  SPI_EXIT_CRITICAL();
  
}
Exemplo n.º 2
0
/**
* @brief  Reset the ERSR status bit.
* @param  None
* @retval Status
*/
uint8_t EepromResetSrwd(void)
{
  uint8_t status;
  uint8_t cmd[] = {EEPROM_CMD_WRSR, EEPROM_STATUS_SRWD};
  //  SPI_ENTER_CRITICAL();
  
  EepromWriteEnable();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow();
  
  //  for(volatile uint16_t i=0;i<CS_TO_SCLK_DELAY;i++);
  
  /* Send command */
  for(uint8_t k=0;k<2;k++)
  {
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, cmd[k]);
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    status = SPI_ReceiveData(s_EepromSpiPort);
  }
  
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
  
  //  SPI_EXIT_CRITICAL();
  return status;
}
Exemplo n.º 3
0
/**
* @brief  Wait polling the SPI until the internal WIP flag is RESET.
*         The flag is SET when a write operation is running.
* @param  None
* @retval None
*/
void EepromWaitEndWriteOperation(void)
{
  uint8_t cmd = EEPROM_CMD_RDSR;
  uint8_t dummy = 0xFF;
  uint8_t status;
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
  /* Send command */
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
  SPI_SendData(Get_EepromSpiPort(), cmd);
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_RXNE) == RESET);
  SPI_ReceiveData(Get_EepromSpiPort());
  
  /* Polling on status register */
  do{
    while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
    SPI_SendData(Get_EepromSpiPort(), dummy);
    while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_RXNE) == RESET);
    status = SPI_ReceiveData(Get_EepromSpiPort());
  }while(status&EEPROM_STATUS_WIP);
  
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
}/* end EepromWaitEndWriteOperation() */
Exemplo n.º 4
0
/**
* @brief  Reset the ERSR status bit.
* @param  None
* @retval Status
*/
uint8_t EepromResetSrwd(void)
{
  uint8_t status;
  uint8_t cmd[] = {EEPROM_CMD_WRSR, EEPROM_STATUS_SRWD};
  
  EepromWriteEnable();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
  /* Send command */
  for(uint8_t k=0;k<2;k++)
  {
    while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
    SPI_SendData(Get_EepromSpiPort(), cmd[k]);
    while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_RXNE) == RESET);
    status = SPI_ReceiveData(Get_EepromSpiPort());
  }
  
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
  return status;
}/* end EepromResetSrwd() */
Exemplo n.º 5
0
/**
* @brief  Write a page of the EEPROM.
*         A page size is 32 bytes.
*         The pages are 256.
*         Page 0 address: 0x0000
*         Page 1 address: 0x0020
*         ...
*         Page 255 address: 0x1FE0
*         It is allowed to write only a page for each operation. If the bytes
*         exceed the single page location, the other bytes are written at the 
*         beginning.
* @param  None
* @retval None
*/
void EepromWrite(uint16_t nAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
{
  uint8_t cmd = EEPROM_CMD_WRITE;
  uint8_t address[2];
  
  /* Wait the end of a previous write operation */
  EepromWaitEndWriteOperation();
  
  /* SET the WREN flag */
  EepromWriteEnable();
  
  for(uint8_t k=0; k<2; k++) {
    address[k] = (uint8_t)(nAddress>>((1-k)*8));
  }
  
  //  SPI_ENTER_CRITICAL();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow();
  
  //  for(volatile uint16_t i=0;i<CS_TO_SCLK_DELAY;i++);
  
  /* Write the header bytes and read the SPIRIT status bytes */
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  SPI_SendData(s_EepromSpiPort, cmd);
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
  SPI_ReceiveData(s_EepromSpiPort);
  
  for(int i=0; i<2; i++)
  {
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, address[i]);
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    SPI_ReceiveData(s_EepromSpiPort);
  }
  
  /* Writes the registers according to the number of bytes */
  for(int index=0; index<cNbBytes; index++)
  {
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, pcBuffer[index]);   
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    SPI_ReceiveData(s_EepromSpiPort);
  }
  
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
  
  //  SPI_EXIT_CRITICAL();
  
}
Exemplo n.º 6
0
/**
* @brief  Read a page of the EEPROM.
*         A page size is 32 bytes.
*         The pages are 256.
*         Page 0 address: 0x0000
*         Page 1 address: 0x0020
*         ...
*         Page 255 address: 0x1FE0
* @param  None
* @retval None
*/
void EepromRead(uint16_t nAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
{
  uint8_t cmd[3];
  cmd[0] = EEPROM_CMD_READ;

  for(uint8_t k=0; k<2; k++) {
    cmd[k+1] = (uint8_t)(nAddress>>((1-k)*8));
  }  
  
  /* Wait the end of a previous write operation */
  EepromWaitEndWriteOperation();
  
  //  SPI_ENTER_CRITICAL();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow();
  
  //  for(volatile uint16_t i=0;i<CS_TO_SCLK_DELAY;i++);
  
  /* Write the header bytes and read the SPIRIT status bytes */
  for(uint8_t i=0; i<3; i++) {
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, cmd[i]);
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    SPI_ReceiveData(s_EepromSpiPort);
  }
  
  /* Read the registers according to the number of bytes */
  for(int index=0; index<cNbBytes; index++)
  {
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
    SPI_SendData(s_EepromSpiPort, 0xFF);
    while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
    *pcBuffer = SPI_ReceiveData(s_EepromSpiPort);
    pcBuffer++;
  }
  
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
  
  //  SPI_EXIT_CRITICAL();
  
}
Exemplo n.º 7
0
/**
* @brief  Set the internal WEL flag to allow write operation.
* @param  None
* @retval None
*/
void EepromWriteEnable(void)
{
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
  /* Send command */
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
  SPI_SendData(Get_EepromSpiPort(), EEPROM_CMD_WREN);
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_RXNE) == RESET);
  SPI_ReceiveData(Get_EepromSpiPort());
  
  while (SPI_GetFlagStatus(Get_EepromSpiPort(), SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin());
  
}/* end EepromWriteEnable() */
Exemplo n.º 8
0
/**
* @brief  Set the internal WEL flag to allow write operation.
* @param  None
* @retval None
*/
void EepromWriteEnable(void)
{
  //  SPI_ENTER_CRITICAL();
  
  /* Put the SPI chip select low to start the transaction */
  EepromSPICSLow();
  
  //  for(volatile uint16_t i=0;i<CS_TO_SCLK_DELAY;i++);
  
  /* Send command */
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  SPI_SendData(s_EepromSpiPort, EEPROM_CMD_WREN);
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_RXNE) == RESET);
  SPI_ReceiveData(s_EepromSpiPort);
  
  while (SPI_GetFlagStatus(s_EepromSpiPort, SPI_FLAG_TXE) == RESET);
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
  
  //  SPI_EXIT_CRITICAL();
  
}