/**
   @brief SPI initialization
   @return none
**/
void SPI_Init(void)
{

   DioPul(pADI_GP0, 0xf8);                    /* Disable the internal pull ups on P0 */

   DioCfg(pADI_GP0, 0x0015);                  /* Configure P0[2:0] for SPI1 */

   DioPulPin(AD7798_CS_PORT, AD7798_CS_PIN_NUMBER, 0);         // Disable the internal pull up on AD7798 CS pin
   DioOenPin(AD7798_CS_PORT, AD7798_CS_PIN_NUMBER, 1);         // Set CS pin for AD7798 as output
   DioSet(AD7798_CS_PORT, AD7798_CS_PIN);

   DioPulPin(ADT7310_CS_PORT, ADT7310_CS_PIN_NUMBER, 0);         // Disable the internal pull up on ADT7310 CS pin
   DioOenPin(ADT7310_CS_PORT, ADT7310_CS_PIN_NUMBER, 1);         // Set CS pin for ADT7310 as output
   DioSet(ADT7310_CS_PORT, ADT7310_CS_PIN);

   DioPulPin(AD5270_CS_PORT, AD5270_CS_PIN_NUMBER, 0);         // Disable the internal pull up on ADT7310 CS pin
   DioOenPin(AD5270_CS_PORT, AD5270_CS_PIN_NUMBER, 1);         // Set CS pin for ADT7310 as output
   DioSet(AD5270_CS_PORT, AD5270_CS_PIN);

   SpiBaud(pADI_SPI1, 9, SPIDIV_BCRST_DIS);   /* Set the SPI1 clock rate in Master mode to x kHz. */

   /* SPI configuration*/
   SpiCfg(pADI_SPI1, SPICON_MOD_TX4RX4, SPICON_MASEN_EN, SPICON_CON_EN | SPICON_SOEN_EN |
          SPICON_RXOF_EN | SPICON_ZEN_EN | SPICON_TIM_TXWR | SPICON_CPOL_HIGH |
          SPICON_CPHA_SAMPLETRAILING | SPICON_ENABLE_EN);

}
void SPIClass::Init()
{
   DioPulPin(pADI_GP0, PIN0, 0);
   DioCfgPin(pADI_GP0, PIN0, 1);        //MISO
   DioPulPin(pADI_GP0, PIN1, 0);
   DioCfgPin(pADI_GP0, PIN1, 1);        //SCLK
   DioPulPin(pADI_GP0, PIN2, 0);
   DioCfgPin(pADI_GP0, PIN2, 1);        //MOSI

   DioPulPin(CS_PORT, CS_PIN_NUMBER, 0);         /* Disable the internal pull up on AD7798 CS pin */
   DioOenPin(CS_PORT, CS_PIN_NUMBER, 1);         /* Set CS pin for AD7798 as output */
   DioSet(CS_PORT, CS_PIN);

   SpiBaud(pADI_SPI1, 9, SPIDIV_BCRST_DIS);   /* Set the SPI1 clock rate in Master mode to x kHz. */

   /* SPI configuration*/
   SpiCfg(pADI_SPI1, SPICON_MOD_TX4RX4, SPICON_MASEN_EN, SPICON_CON_EN | SPICON_SOEN_EN |
          SPICON_RXOF_EN | SPICON_ZEN_EN | SPICON_TIM_TXWR | SPICON_CPOL_HIGH |
          SPICON_CPHA_SAMPLETRAILING | SPICON_ENABLE_EN);

}
Ejemplo n.º 3
0
/*********************************************************************
* Function: void APP_DeviceCustomHIDTasks(void);
*
* Overview: Keeps the Custom HID demo running.
*
* PreCondition: The demo should have been initialized and started via
*   the APP_DeviceCustomHIDInitialize() and APP_DeviceCustomHIDStart() demos
*   respectively.
*
* Input: None
*
* Output: None
*
********************************************************************/
void APP_DeviceCustomHIDTasks()
{   
    //Check if we have received an OUT data packet from the host
    if(HIDRxHandleBusy(USBOutHandle) == false)
    {   
        //We just received a packet of data from the USB host.
        //Check the first uint8_t of the packet to see what command the host
        //application software wants us to fulfill.
        switch(ReceivedDataBuffer[0])				//Look at the data the host sent, to see what kind of application specific command it sent.
        {
            case READ_SFR:

                ReadSfr();
                break;

            case WRITE_SFR:

                WriteSfr();
                break;

            case ADC_CFG:

                AdcCfg();
                break;

            case ADC_VALUE:

                AdcValue();
                break;

            case ANALOGCMP_CFG:

                AnalogCmpCfg();
                break;

            case SPI_CFG:

                SpiCfg();
                break;

            case SPI_TRANSFERENCE:

                SpiTransference();
                break;

            case SFR_CHANGE_BIT_VALUE:

                SfrChangeBitValue();
                break;

            case I2C_CFG:

                I2cCfg();
                break;

            case I2C_TRANSFERENCE:

                I2cTransference();
                break;

            case CCP_CFG:

                CcpCfg();
                break;

            case PWM_FPWM:

                PwmFpwm();
                break;

            case PWM_DC:

                PwmDc();
                break;

            case SFR_READ_BIT_VALUE:

                SfrReadBitValue();
                break;

            case EUSART_TX:

                EusartTx();
                break;

            case EUSART_RX:

                EusartRx();
                break;

            case TEST:

                Test();
                break;

            case UDF_CALL:

                UDF();
                break;

            case UDF_PROGRAM:

                UDF_Program();
                break;
        }
        //Re-arm the OUT endpoint, so we can receive the next OUT data packet 
        //that the host may try to send us.
        USBOutHandle = HIDRxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ReceivedDataBuffer, 64);
    }
}