SHARE
TWEET

Untitled

a guest Jun 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Flash1_TestWrite()
  2.  
  3. {
  4.     uint32_t num_of_bytes, loop, dataCount;
  5.  
  6.     flashData.TXbuffer[0] = 0x02; // Write Flash Page1 address 0x0000
  7.     flashData.TXbuffer[1] = 0x00;
  8.     flashData.TXbuffer[2] = 0x00;
  9.     flashData.TXbuffer[3] = 0x00;
  10.  
  11.     dataCount = 4;
  12.  
  13.     for(loop =0; loop < 20; loop ++)
  14.     {
  15.         flashData.TXbuffer[dataCount++] = 0xAA;
  16.     }
  17.  
  18.     num_of_bytes = dataCount; //opcode + address + data
  19.  
  20.     Flash1_WREN(); / /Enable Write
  21.  
  22.     nFlashCS1Off();
  23.     Flash1_Write_Buffer_Handle = DRV_SPI_BufferAddWrite(SPIHandle,(SPI_DATA_TYPE *) &flashData.TXbuffer[0], num_of_bytes, 0, 0);
  24.    if (DRV_SPI_BUFFER_EVENT_COMPLETE & DRV_SPI_BufferStatus(Flash1_Write_Buffer_Handle))
  25.    {
  26.       nFlashCS1On();
  27.    }
  28. }
  29.  
  30.  
  31.  
  32. voidFlash1_Read( void )
  33. {
  34.     switch(flashData.state)
  35.     {
  36.         uint32_t num_of_bytes, loop, dataCount;
  37.  
  38.         case FLASH1_INIT:
  39.         {
  40.              nFlashCS1On();
  41.              flashData.state = FLASH1_SEND_READ_CMD;
  42.             break;
  43.         }
  44.         case FLASH1_SEND_READ_CMD:
  45.         {
  46.             flashData.TXbuffer[0] = 0x03; // Read Page
  47.             flashData.TXbuffer[1] = 0x00;
  48.             flashData.TXbuffer[2] = 0x00; // Address - MSB
  49.             flashData.TXbuffer[3] = 0x00; // Address - LSB
  50.  
  51.             dataCount = 4;
  52.  
  53.             for(loop =0; loop < 20; loop ++)
  54.             {
  55.                 flashData.TXbuffer[dataCount++] = 0xFF; // dummy bytes
  56.             }
  57.  
  58.             num_of_bytes = dataCount;
  59.             nFlashCS1Off();
  60.  
  61.             Flash1_Write_Buffer_Handle = DRV_SPI_BufferAddWrite(SPIHandle, (SPI_DATA_TYPE *) &flashData.TXbuffer[0], num_of_bytes, 0, 0);
  62.  
  63.             flashData.state = FLASH1_WAIT_FOR_REPLY;
  64.             break;
  65.         }
  66.  
  67.         case FLASH1_WAIT_FOR_REPLY:
  68.         {
  69.             if(DRV_SPI_BUFFER_EVENT_COMPLETE &
  70.                                DRV_SPI_BufferStatus(Flash1_Write_Buffer_Handle))
  71.             flashData.state = FLASH1_GET_DATA;
  72.             break;
  73.         }
  74.  
  75.       case FLASH1_GET_DATA:
  76.         {
  77.             Flash1_Read_Buffer_Handle = DRV_SPI_BufferAddRead( SPIHandle, (SPI_DATA_TYPE *) &flashData.RXbuffer[0], 24, 0, 0);
  78.            flashData.state = FLASH1_WAIT_FOR_DATA;
  79.            break;
  80.         }
  81.  
  82.       case FLASH1_WAIT_FOR_DATA:
  83.         {
  84.             if(DRV_SPI_BUFFER_EVENT_COMPLETE &
  85.                                DRV_SPI_BufferStatus (Flash1_Read_Buffer_Handle))
  86.             {
  87.                 nFlashCS1On(); // Assert CS line
  88.                 flashData.state = FLASH1_READ_COMPLETE;
  89.             }
  90.            break;
  91.         }
  92.  
  93.       case FLASH1_READ_COMPLETE:
  94.       {
  95.         break;
  96.       }
  97.  
  98.       default:
  99.         break;
  100.     }
  101.     return false;
  102. }
  103.      
  104. for(loop =0; loop < 20; loop ++) { flashData.TXbuffer[dataCount++] = 0xFF; // dummy bytes }
  105.      
  106. Flash1_Write_Buffer_Handle = DRV_SPI_BufferAddWrite(SPIHandle, (SPI_DATA_TYPE *) &flashData.TXbuffer[0], num_of_bytes, 0, 0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top