/**
  * @brief  Read register value.
  * @param  Reg
  * @retval None
  */
uint16_t LCD_IO_ReadData(uint16_t Reg) 
{
  uint32_t readvalue = 0;

  /* Change BaudRate Prescaler 8 for Read */
  /* Mean SPI baudrate is set to 72/8 = 9 MHz */
  heval_Spi.Instance->CR1 &= 0xFFC7;
  heval_Spi.Instance->CR1 |= SPI_BAUDRATEPRESCALER_8;
  
  /* Send Reg value to Read */
  LCD_IO_WriteReg(Reg);

  /* Reset LCD control line(/CS) and Send command */
  LCD_CS_LOW();
  
  /* Send Start Byte */
  SPIx_Write(START_BYTE | LCD_READ_REG);

  /* Read Upper Byte */
  SPIx_Write(0xFF);
  readvalue = SPIx_Read();
  readvalue = readvalue << 8;
  readvalue |= SPIx_Read();
  
  /* Recover Baud Rate initial value */
  heval_Spi.Instance->CR1 &= 0xFFC7;
  heval_Spi.Instance->CR1 |= heval_Spi.Init.BaudRatePrescaler;

  HAL_Delay(10);

  /* Deselect : Chip Select high */
  LCD_CS_HIGH();
  return readvalue;
}
示例#2
0
/**
  * @brief  Read register value.
  * @param  Reg
  * @retval None
  */
uint16_t LCD_IO_ReadData(uint16_t Reg) 
{
  uint32_t readvalue = 0;

  /* Send Reg value to Read */
  LCD_IO_WriteReg(Reg);

  /* Reset LCD control line(/CS) and Send command */
  LCD_CS_LOW();
  
  /* Send Start Byte */
  SPIx_Write(START_BYTE | LCD_READ_REG);

  /* Read Upper Byte */
  SPIx_Write(0xFF);
  readvalue = SPIx_Read();
  readvalue = readvalue << 8;
  readvalue |= SPIx_Read();
  
  HAL_Delay(10);

  /* Deselect : Chip Select high */
  LCD_CS_HIGH();
  return readvalue;
}
/**
  * @brief  Wait response from the SPI EEPROM
  * @param  None
  * @retval HAL_StatusTypeDef HAL Status
  */
HAL_StatusTypeDef EEPROM_SPI_IO_WaitEepromStandbyState(void)
{
  uint32_t timeout = 0xFFFF;
  uint32_t eepromstatus;
  
  /*!< Select the EEPROM: Chip Select low */
  EEPROM_CS_LOW();
  
  /*!< Send "Read Status Register" instruction */
  SPIx_Write(EEPROM_CMD_RDSR);

  /*!< Loop as long as the memory is busy with a write cycle */
  do
  {
    /*!< Send a dummy byte to generate the clock needed by the EEPROM
    and put the value of the status register in EEPROM Status variable */
    eepromstatus = SPIx_Read();
    timeout --;
  }
  while (((eepromstatus & EEPROM_WIP_FLAG) == SET) && timeout); /* Write in progress */

  /*!< Deselect the EEPROM: Chip Select high */
  EEPROM_CS_HIGH();

  if ((eepromstatus & EEPROM_WIP_FLAG) != SET)
  {
    /* Right response got */
    return HAL_OK;
  }
  else
  {
    /* After time out */
    return HAL_TIMEOUT;
  }
}
/**
  * @brief  Read data from SPI EEPROM driver
  * @param  MemAddress: Internal memory address
  * @param  pBuffer: Pointer to data buffer
  * @param  BufferSize: Amount of data to be read
  * @retval HAL_StatusTypeDef HAL Status
  */
HAL_StatusTypeDef EEPROM_SPI_IO_ReadData(uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
{
  /*!< Select the EEPROM: Chip Select low */
  EEPROM_CS_LOW();
 
  /*!< Send "Write to Memory " instruction */
  SPIx_Write(EEPROM_CMD_READ);
  
  /*!< Send MemAddress high nibble address byte to write to */
  SPIx_Write((MemAddress & 0xFF0000) >> 16);
  
  /*!< Send WriteAddr medium nibble address byte to write to */
  SPIx_Write((MemAddress & 0xFF00) >> 8);
  
  /*!< Send WriteAddr low nibble address byte to write to */
  SPIx_Write(MemAddress & 0xFF);
  
  while ((BufferSize)--) /*!< while there is data to be read */
  {
    /*!< Read a byte from the EEPROM */
    *pBuffer = SPIx_Read();
    /*!< Point to the next location where the byte read will be saved */
    pBuffer++;
  }
  
  /*!< Deselect the EEPROM: Chip Select high */
  EEPROM_CS_HIGH();

  return HAL_OK;
}
/**
  * @brief  Reads a byte from the SD.
  * @retval The received byte.
  */
uint8_t SD_IO_ReadByte(void)
  {
  uint8_t data = 0;
  
  /* Get the received data */
  data = SPIx_Read();

  /* Return the shifted data */
  return data;
}
/**
  * @brief  Reads a byte from the SD.
  * @param  None
  * @retval The received byte.
  */
uint8_t SD_IO_ReadByte(void)
{
  uint8_t data = 0;
  
  /* Change BaudRate Prescaler 4 for Read */
  /* Mean SPI baudrate is set to 72/4 = 18 MHz */
  heval_Spi.Instance->CR1 &= 0xFFC7;
  heval_Spi.Instance->CR1 |= SPI_BAUDRATEPRESCALER_4;

  /* Get the received data */
  data = SPIx_Read();

  /* Return the shifted data */
  return data;
}
/**
  * @brief  Reads register value.
  * @param  RegValue Address of the register to read
  * @param  ReadSize Number of bytes to read
  * @retval Content of the register value
  */
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) 
{
  uint32_t readvalue = 0;

  /* Select: Chip Select low */
  LCD_CS_LOW();

  /* Reset WRX to send command */
  LCD_WRX_LOW();
  
  SPIx_Write(RegValue);
  
  readvalue = SPIx_Read(ReadSize);

  /* Set WRX to send data */
  LCD_WRX_HIGH();

  /* Deselect: Chip Select high */
  LCD_CS_HIGH();
  
  return readvalue;
}