Example #1
0
void Mcp6s26SetGain(Mcp6s26Gain_t gain)
{
    MCP6S26_CS_LOW

    SpiTx(MCP6S26_SPI_BUS, 0x40); // M1 = 1, A0 = 0
    SpiTx(MCP6S26_SPI_BUS, 1);

    MCP6S26_CS_HIGH
            
}
Example #2
0
void Mcp6s26SetChannel(UI08_t channel)
{
    //
    MCP6S26_CS_LOW

    SpiTx(MCP6S26_SPI_BUS, 0x41); // M1 = 1, A0 = 1
    SpiTx(MCP6S26_SPI_BUS, channel);

    MCP6S26_CS_HIGH
            
}
void SPIClass::Write(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber)
{

    uint8_t byte = 0, reset = 0;

    uint16_t ui16fifo_status;

    if(bytesNumber == 8){

       bytesNumber = 4;
       reset = 1;
    }
    ui16fifo_status = (bytesNumber << 8);                                /* Set FIFO status correct value */

    if(slaveDeviceId == 0)
       DioClr(CS_PORT, CS_PIN);

       /* Flush Tx and Rx FIFOs */
       SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);

       for(byte = 0;byte < bytesNumber;byte++)
       {
             SpiTx(pADI_SPI1, data[byte]);
       }

       /* Wait until x bytes are received */
       while ((SpiSta(pADI_SPI1) & ui16fifo_status) != ui16fifo_status);

       if(reset == 1){

             SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);

             for(byte = 0;byte < bytesNumber;byte++)
             {
                   SpiTx(pADI_SPI1, data[byte]);
             }


             while ((SpiSta(pADI_SPI1) & ui16fifo_status) != ui16fifo_status);
       }

       if(slaveDeviceId == 0)
         DioSet(CS_PORT, CS_PIN);

}
/***************************************************************************
 * @brief Writes data to SPI.
 *
 * @param data - Write data buffer:
 *               - first byte is the chip select number;
 *               - from the second byte onwards are located data bytes to write.
 * @param bytesNumber - Number of bytes to write.
 *
 * @return Number of written bytes.
*******************************************************************************/
void SPI_Write(unsigned char* data, unsigned char bytesNumber, enChannels ch)
{

    uint8_t byte = 0;

    uint16_t ui16fifo_status = (bytesNumber << 8);                                /* Set FIFO status correct value */

    if(convFlag == 0){

          switch(ch){
             case AD7798:
                 DioClr(AD7798_CS_PORT, AD7798_CS_PIN);
                break;
             case ADT7310:
                 DioClr(ADT7310_CS_PORT, ADT7310_CS_PIN);
                break;
             default:
               {
                  if(daisyCh == 0)
                     DioClr(AD5270_CS_PORT, AD5270_CS_PIN);
               }
                break;
          }
    }

    /* Flush Tx and Rx FIFOs */
    SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);

    for(byte = 0;byte < bytesNumber;byte++)
    {
          SpiTx(pADI_SPI1, data[byte]);
    }

    /* Wait until x bytes are received */
    while ((SpiSta(pADI_SPI1) & ui16fifo_status) != ui16fifo_status);

    if(convFlag == 0){

          switch(ch){
             case AD7798:
                 DioSet(AD7798_CS_PORT, AD7798_CS_PIN);
                break;
             case ADT7310:
                 DioSet(ADT7310_CS_PORT, ADT7310_CS_PIN);
                break;
             default:
               {
                  if(daisyCh == 0)
                     DioSet(AD5270_CS_PORT, AD5270_CS_PIN);
               }
                break;
          }
    }

}
/***************************************************************************//**
 * @brief Reads data from SPI.
 *
 * @param data - As an input parameter, data represents the write buffer:
 *               - first byte is the chip select number;
 *               - from the second byte onwards are located data bytes to write.
 *               As an output parameter, data represents the read buffer:
 *               - from the first byte onwards are located the read data bytes.
 * @param bytesNumber - Number of bytes to write.
 *
 * @return Number of written bytes.
*******************************************************************************/
void SPIClass::Read(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber)
{

   unsigned char writeData[4]  = {0, 0, 0, 0};
   unsigned char byte          = 0;
   uint16_t ui16fifo_status;


   ui16fifo_status = ((bytesNumber) << 8);             /* Set FIFO status correct value */

    for(byte = 0;byte < bytesNumber;byte++)
    {
        if(byte == 0)
           writeData[byte] = data[byte];
        else
           writeData[byte] = 0xAA;    /* dummy value */
    }

    if(slaveDeviceId == 0)
       DioClr(CS_PORT, CS_PIN);

    SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);

    for(byte = 0;byte < bytesNumber;byte++)
    {
       SpiTx(pADI_SPI1, writeData[byte]);
    }

    /* Wait until x bytes are received */
    while ((SpiSta(pADI_SPI1) & ui16fifo_status) != ui16fifo_status);

    for(byte = 0;byte < bytesNumber;byte++)
    {
        data[byte] = SpiRx(pADI_SPI1);
    }

    if(slaveDeviceId == 0)
       DioSet(CS_PORT, CS_PIN);
}
/***************************************************************************//**
 * @brief Reads data from SPI.
 *
 * @param data - As an input parameter, data represents the write buffer:
 *               - first byte is the chip select number;
 *               - from the second byte onwards are located data bytes to write.
 *               As an output parameter, data represents the read buffer:
 *               - from the first byte onwards are located the read data bytes.
 * @param bytesNumber - Number of bytes to write.
 *
 * @return Number of written bytes.
*******************************************************************************/
void SPI_Read(unsigned char* data, unsigned char bytesNumber, enChannels ch)
{

   unsigned char writeData[4]  = {0, 0, 0, 0};
   unsigned char byte          = 0;
   uint16_t ui16fifo_status = ((bytesNumber + 1) << 8);             /* Set FIFO status correct value */

    for(byte = 0;byte <= bytesNumber;byte++)
    {
        if(byte == 0)
           writeData[byte] = data[byte];
        else
           writeData[byte] = 0xAA;    /* dummy value */
    }

    if(convFlag == 0){

          switch(ch){
             case AD7798:
                 DioClr(AD7798_CS_PORT, AD7798_CS_PIN);
                break;
             case ADT7310:
                 DioClr(ADT7310_CS_PORT, ADT7310_CS_PIN);
                break;
             default:
                 DioClr(AD5270_CS_PORT, AD5270_CS_PIN);
                break;
          }

    }
    SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);

    for(byte = 0;byte <= bytesNumber;byte++)
    {
       SpiTx(pADI_SPI1, writeData[byte]);
    }

    /* Wait until x bytes are received */
    while ((SpiSta(pADI_SPI1) & ui16fifo_status) != ui16fifo_status);

    data[0] = writeData[0] = SpiRx(pADI_SPI1);           /* Dummy read, not needed value */

    for(byte = 0;byte < bytesNumber;byte++)
    {
        data[byte] = writeData[byte] = SpiRx(pADI_SPI1);
    }

    if(convFlag == 0){

          switch(ch){
             case AD7798:
                 DioSet(AD7798_CS_PORT, AD7798_CS_PIN);
                break;
             case ADT7310:
                 DioSet(ADT7310_CS_PORT, ADT7310_CS_PIN);
                break;
             default:
                DioSet(AD5270_CS_PORT, AD5270_CS_PIN);
                break;
          }
    }

}