Send 16 bit via USBFS

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
feme_285141
Level 4
Level 4

Hello

I would like to send 16 bit of an ADC, but when sending it it sends 8bit. The ADC I have it configured to send 16 bit.

What do you think is the problem?

Here is the code:

#include <project.h>

#define EP_1 0x1

#define EP_2 0x2

int main()

{

     /* Data buffers. */

    uint8 buffer_IN[0];     // salida de datos del ADC

    uint16 adcReading = 0u;

   

    /*Habilita las interrupciones globales */

    CyGlobalIntEnable;

    /*Iniciamos USBFS Operación para el DEVICE_ID y con 5V operación.*/

    USBFS_Start(0, USBFS_DWR_VDDD_OPERATION);

    /*Asegúrese de que el dispositivo esté configurado antes de ejecutar el código.*/

    while(USBFS_GetConfiguration() == 0x00)

    {

/*Esperando a que se configure el dispositivo*/

}

       

    /*Iniciamos el ADC*/

    ADC_Start();

       

    for (;;)

    {

        // Comprueba si IN Endpoint está vacío. Si es así, cárguelo con los datos que se transferirán

if(USBFS_IN_BUFFER_EMPTY == USBFS_GetEPState(EP_1))

        { /*Cargar datos ubicados en IN_Data_Buffer y cargarlos en el Endpoint IN*/

USBFS_LoadInEP(EP_1, &buffer_IN[0], 12);

}

       

      

        ADC_StartConvert(); // Iniciamos la conversión de datos del ADC

        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);// Esperamos los resultados del ADC

        adcReading = ADC_GetResult16(); // Datos de ADD

   

        buffer_IN[0] = adcReading; //se preparan los datos para enveiar por AD

       

   

       

    }

}

/* [] END OF FILE */

0 Likes
1 Solution
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

If you want to send 12 bytes of data, please prepare a buffer which size is greater than 12 at least.

    uint8 buffer_IN[12];     // salida de datos del ADC

The buffer is an array of 8-bit (uint8) data.  So, it is not possible to store a 16-bit data into an element of the array.  If you want to store a 16-bit data into the 8-bit array, two elements must be used at least.

buffer_IN[0] = LO8(adcReading);

buffer_IN[1] = HI8(adcReading);

LO8() and HI8() are a MACRO to return LSB and MSB part of a 16-bit value.

Regards,

Noriaki

View solution in original post

1 Reply
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

If you want to send 12 bytes of data, please prepare a buffer which size is greater than 12 at least.

    uint8 buffer_IN[12];     // salida de datos del ADC

The buffer is an array of 8-bit (uint8) data.  So, it is not possible to store a 16-bit data into an element of the array.  If you want to store a 16-bit data into the 8-bit array, two elements must be used at least.

buffer_IN[0] = LO8(adcReading);

buffer_IN[1] = HI8(adcReading);

LO8() and HI8() are a MACRO to return LSB and MSB part of a 16-bit value.

Regards,

Noriaki