Chat freely about anything...

User avatar
By Mohanraj M
#41871 Hi,
I need to read and write data from SPI flash. I am using spi_flash_read and spi_flash_write API's for read and write data. Both read and write data returns success response but unable to print the read data which was stored. Please provide me a solution to get the data which was saved.
Code: Select allsave_data(const char *name)
{
   char buff[4]={0};
   int result = -1;
   uint64_t temp;
   char *start;
   strcpy(buff,name);
   result = spi_flash_write(0x5C000,(uint32*)&buff,1);
   if(result == SPI_FLASH_RESULT_ERR)
        {
                printf("\nWrite failed...\n");
        }
        else if(result == SPI_FLASH_RESULT_OK)
        {
                printf("\nWrite success...\n");
                read_data();
        }
}


read_data()
{
   int result = -1;
   char buff[5] = {0};
   result= spi_flash_read(0x5C000,(uint32*)&buff,5);
   if(result == SPI_FLASH_RESULT_ERR)
   {
      printf("\nRead failed...321\n");   
   }
   else if(result == SPI_FLASH_RESULT_OK)
   {
      printf("\nRead success...\n");
      printf("Data  : %s\n",buff);  /*PRINTS A GARBAGE VALUE*/
   }
}