Guest User

Untitled

a guest
Feb 4th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include "common.h"
  2. static uint8_t tx_buffer[TR_BUFF_SIZE];
  3. static uint8_t rx_buffer[TR_BUFF_SIZE];
  4.  
  5. int main()
  6. {
  7.     uint32_t rx_sum = 0;
  8.     uint32_t tx_sum = 0;
  9.     uint8_t tmp;
  10.     uint32_t tx_crc = 0;
  11.     uint32_t tx_crc_old = 0;
  12.     uint32_t a = 364;
  13.     uint32_t b = 53457;
  14.     uint32_t c = 976;
  15.     uint32_t d = 66;
  16.  
  17.  
  18.     init();
  19.     // initialize buffers with some known value
  20.     memset(tx_buffer,0x33,sizeof(tx_buffer));
  21.     memset(rx_buffer,0x44,sizeof(rx_buffer));
  22.  
  23.     // wait for keystroke: this gives the user time to start the slave
  24.     Report("Start the slave and press any key to transmit data....\n\r");
  25.     MAP_UARTCharGet(UARTA0_BASE);
  26.    
  27.     // configure SPI channel
  28.     MAP_SPIReset(GSPI_BASE);
  29.     MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI),
  30.                      SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_0,
  31.                      (SPI_SW_CTRL_CS |
  32.                      SPI_4PIN_MODE |
  33.                      SPI_TURBO_OFF |
  34.                      SPI_CS_ACTIVEHIGH |
  35.                      SPI_WL_8));   
  36.     MAP_SPIEnable(GSPI_BASE);
  37.    
  38.     tx_crc = fill_buffer(tx_buffer,TR_BUFF_SIZE,"TX");
  39.  
  40.     while(1)
  41.     {
  42.         tx_crc_old = tx_crc;
  43.         change_seed(a++,b++,c++,d++);
  44.         tx_crc = fill_buffer(tx_buffer,TR_BUFF_SIZE,"TX");
  45.         Message("Sending...");
  46.         //MAP_SPITransfer(GSPI_BASE,tx_buffer,rx_buffer, TR_BUFF_SIZE,
  47.         //      SPI_CS_ENABLE|SPI_CS_DISABLE);
  48.         SPICSEnable(GSPI_BASE);
  49.         for(int i = 0; i < TR_BUFF_SIZE; i++)
  50.         {
  51.             SPIDataPut(GSPI_BASE,tx_buffer[i]);
  52.             //Message("x");
  53.             SPIDataGet(GSPI_BASE,&rx_buffer[i]);
  54.         }
  55.         Message("Transfer complete!\n\r");
  56.         SPICSDisable(GSPI_BASE);
  57.  
  58.         rx_sum = 0;
  59.         for(int i = 0; i < TR_BUFF_SIZE; i++)
  60.         {
  61.             rx_sum += rx_buffer[i];
  62.         }
  63.         Report("\n\rChecksum in the RX buffer was: 0x%02x, we send 0x%02x\n\r\n\r",crc(rx_buffer),tx_crc_old);
  64.         //Report("The sum in the Rx buffer is: %d, tx was : %d\n\r",rx_sum,tx_sum);
  65.         Message("TX-");
  66.         print_buffer(tx_buffer,TR_BUFF_SIZE);
  67.         Message("RX-");
  68.         print_buffer(rx_buffer,TR_BUFF_SIZE);      
  69.         Report("Press any key to transmit again\n\r");
  70.         MAP_UARTCharGet(UARTA0_BASE);
  71.     }
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment