Skip to main content
karoui2
Visitor II
March 24, 2013
Question

Sending data from stm32f4 to pc

  • March 24, 2013
  • 1 reply
  • 810 views
Posted on March 24, 2013 at 20:27

hi,

i am trying to send data from accelerometer to pc using virtual com port ,but when i open hyper terminal to check if data was sent i found out unsignificant symbols!!!

this is the  systick handler wich is called when an interruption is generated 

void SysTick_Handler(void)

{

 uint8_t temp1, temp2 = 0;

  if (TimingDelay != 0x00)

  {

    TimingDelay_Decrement();

  }

  else

  {

    Counter ++;

    if (Counter == 10)

    {

      Buffer[0] = 0;

      Buffer[2] = 0;

      /* Disable All TIM4 Capture Compare Channels */

      TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE);

      TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE);

      TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE);

      TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE);

      LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6);

  //routine used to send data via vcp!!!

      DISCOVERY_EXTI_IRQHandler();

      /* Remove the offsets values from data */

      Buffer[0] -= XOffset;

      Buffer[2] -= YOffset;

      /* Update autoreload and capture compare registers value*/

      temp1 = ABS((int8_t)(Buffer[0]));

      temp2 = ABS((int8_t)(Buffer[2]));

      TempAcceleration = MAX(temp1, temp2);

      if(TempAcceleration != 0)

      {

        if ((int8_t)Buffer[0] < -2)

        {

          /* Enable TIM4 Capture Compare Channel 4 */

          TIM_CCxCmd(TIM4, TIM_Channel_4, ENABLE);

          /* Sets the TIM4 Capture Compare4 Register value */

          TIM_SetCompare4(TIM4, TIM_CCR/TempAcceleration);

        }

        if ((int8_t)Buffer[0] > 2)

        {

          /* Enable TIM4 Capture Compare Channel 2 */

          TIM_CCxCmd(TIM4, TIM_Channel_2, ENABLE);

          /* Sets the TIM4 Capture Compare2 Register value */

          TIM_SetCompare2(TIM4, TIM_CCR/TempAcceleration);

        }

        if ((int8_t)Buffer[2] > 2)

        {

          /* Enable TIM4 Capture Compare Channel 1 */

          TIM_CCxCmd(TIM4, TIM_Channel_1, ENABLE);

          /* Sets the TIM4 Capture Compare1 Register value */

          TIM_SetCompare1(TIM4, TIM_CCR/TempAcceleration);

        }

        if ((int8_t)Buffer[2] < -2)

        {

          /* Enable TIM4 Capture Compare Channel 3 */

          TIM_CCxCmd(TIM4, TIM_Channel_3, ENABLE);

          /* Sets the TIM4 Capture Compare3 Register value */

          TIM_SetCompare3(TIM4, TIM_CCR/TempAcceleration);

        }

        /* Time base configuration */

        TIM_SetAutoreload(TIM4,  TIM_ARR/TempAcceleration);

        /* Read click status register */

        LIS302DL_Read(&ClickReg, LIS302DL_CLICK_SRC_REG_ADDR, 1);

        if(ClickReg == SINGLECLICK_Z)

        {

          SingleClickDetect = 0x01;

        }

      }

      Counter = 0x00;

    }

  }

and this is the vcp_DataTx function used to send data to USB port :

static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)

{

 uint32_t i=0;

 for( i = 0; i < Len; i++ )

  {

   APP_Rx_Buffer[APP_Rx_ptr_in] = (uint8_t) Buf[i];

   APP_Rx_ptr_in++;

   if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)

   {

    APP_Rx_ptr_in = 0;

   }

  }

   return USBD_OK;

}

this function is called into this one :

 void DISCOVERY_EXTI_IRQHandler(void)

{

VCP_DataTx (Buffer[0], 1);

}

thanks in advance .
    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    March 25, 2013
    Posted on March 25, 2013 at 01:25

    I'm not sure I fully understand the point of all that, or what TIM4 is doing, or how, but you're not going to be emitting ASCII data. You look to be trying to send an 8-bit value stored in Buffer[0], which could easily be control characters, or look like other random gibberish in a Hyper Terminal screen. Considered RealTerm printing hex characters?

    If you want to get nice signed decimal data out, then you'll need to process the numbers, output the sign, and decode into decimal digits.

    Also, be cautious about home much you're doing in the SysTick interrupt, I'm not clear of the periodicity of it, or the time it takes to read from the SPI interface here.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..