SPI interface STM-32 cc3200 and tdc gp-22

Discussion in 'Embedded Systems and Microcontrollers' started by Bharath.R, Feb 17, 2015.

  1. Bharath.R

    Thread Starter New Member

    Feb 17, 2015
    2
    0
    0 down vote favorite

    i have been trying to interface between cc3200 and tdc gp-22,in which i got example code for tdc gp-22 which is written for STM32F105_VC microprocessor.

    The attached function is used for " Reads n bytes from an address in GP22". In this function i cant understand the part from "compulsory reads to DR and SR to clear OVR so incoming next data is saved" which is specified as comments.Why SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE); is used again. Whats the use of sending 0x00FF and recieving bus_type and whats the use of setting "while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_RXNE)==0)"

    OR

    can somebody explain how actually the spi interfacing takes place as i cant able to clearly understand the process going on between transmission and reciever buffer .Why is transmitter buffer is checked empty and reciver buffer is checked as not empty??. CAN SOMEONE HELP PLS?!!

    This is the link to STM-32 module for reference http://www.disca.upv.es/aperles/arm_cortex_m3/curset/STM32F4xx_DSP_StdPeriph_Lib_V1.0.1/html/modules.html

    Code (Text):
    1. float gp22_read_n_bytes(void *bus_type, uint8_t n_bytes, uint8_t read_opcode,
    2.                    uint8_t read_addr, uint8_t fractional_bits)
    3. {
    4.   uint32_t    Result_read = 0;
    5.   float       Result = 0;
    6.   uint8_t     read_opcode_addr = read_opcode | read_addr;
    7.  
    8.   //.............. Result = n Byte = n x 8 bits......................
    9.   if (bus_type==SPI1 | bus_type==SPI2)
    10.   {
    11.        // Deactivating Reset SPIx
    12.        if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
    13.        if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
    14.    
    15.        SPI_I2S_SendData(bus_type, read_opcode_addr);  // READ OPCODE + Address
    16.      
    17.        while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==RESET) {};
    18.   Simple_delay_750ns((void*)10); // important delay (16) at SPI freq.=750kHz
    19.      
    20.        //Compulsory reads to DR and SR to clear OVR,
    21.        //so that next incoming data is saved
    22.        SPI_I2S_ReceiveData(bus_type);                     // To clear OVR
    23.        SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE); // To clear OVR
    24.  
    25.          //Reading byte1
    26.          SPI_I2S_SendData(bus_type, 0x00FF);  // DUMMY WRITE
    27.          // Wait until RX buffer is not empty, then read the received data
    28.          while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_RXNE)==0) {}
    29.          Result_read = SPI_I2S_ReceiveData(bus_type); //  Read
    30.  
    31.        for (int n = 1; n < n_bytes; n++)
    32.        {    
    33.          //Reading byte2 .. byte.n
    34.          SPI_I2S_SendData(bus_type, 0x00FF);  // DUMMY WRITE
    35.          // Wait until RX buffer is not empty, then read the received data
    36.          while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_RXNE)==0) {}
    37.  
    38.          Result_read = Result_read<<8;
    39.          Result_read |= SPI_I2S_ReceiveData(bus_type); //  Read
    40.        }
    41.  
    42.        // Reset to device SPIx
    43.        if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
    44.        if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);
    45.   }
    46.  
    47.   Result = Result_read / pow(2, fractional_bits);
    48.  
    49.   return Result;
    50. }                
     
Loading...