/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Can not detect USART 2 signal at Extension Connector with Oscilloscope

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 primer
  •  » Can not detect USART 2 signal at Extension Connector with Oscilloscope

# 1   2010-09-24 11:05:47 Can not detect USART 2 signal at Extension Connector with Oscilloscope

jkwool
New member
Registered: 2010-07-16
Posts: 3

Can not detect USART 2 signal at Extension Connector with Oscilloscope

Hi,
I am working on an application for the Primer 2 that will use USART2 to communicate with another microcontroller.

I have set up a project to test the USART functionality, I have an extension board connected to the Primer 2. When i run the following code I can not seem to detect the serial message signal at the TX pin on the extension connector with my Oscilloscope?

Am i doing something wrong in my code or is this a hardware problem?


/********************** (C) COPYRIGHT 2007-2009 RAISONANCE ********************
* File Name          :  Application.c
* Author             :
* Date First Issued  :
* Description        :  Circle_App CircleOS application template.
* Revision           :
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/

#include "stm32f10x_usart.h"
#include "stm32f10x_conf.h"
#include "stm32f10x_lib.h"
#include "stm32f10x_map.h"
#define __STM32F10x_H
#include "stm32f10x_lib.h"
#include "circle_api.h"
/* Private defines -----------------------------------------------------------*/

void RCC_Config(void);
void USART_Config(void);
void Timer_Init(void);
void Send_Byte(u8 Txbyte);

// The following should be the minimal CircleOS version needed by your application
#define NEEDEDVERSION "V 3.7"

/* Private functions ---------------------------------------------------------*/
static enum MENU_code MsgVersion(void);

/* Public variables ----------------------------------------------------------*/
const char Application_Name[8+1] = {"Serial"};      // Max 8 characters

/* Private Variables */
ErrorStatus HSEStartUpStatus;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;

/*******************************************************************************
* Function Name  : Application_Ini
* Description    : Initialization function of Circle_App. This function will
*                  be called only once by CircleOS.
* Input          : None
* Return         : MENU_CONTINUE_COMMAND
*******************************************************************************/
enum MENU_code Application_Ini(void)
    {
    // Ensure that the current OS version is recent enough
    if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
        {
        return MsgVersion();
        }

    Timer_Init();
   
    RCC_Config();

    USART_Config();

    return MENU_CONTINUE_COMMAND;
   
    }

/*******************************************************************************
* Function Name  : Application_Handler
* Description    : Management of the Circle_App.
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler(void)
{
    Send_Byte(0x80);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x80);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);
    Send_Byte(0x81);
    Send_Byte(0x82);
    Send_Byte(0x83);

#if 1
    // If the button is pressed, the application is exited
    if(BUTTON_GetState() == BUTTON_PUSHED)
        {
        BUTTON_WaitForRelease();
        return MENU_Quit();
        }
#endif

    return MENU_CONTINUE;   // Returning MENU_LEAVE will quit to CircleOS
    }

/*******************************************************************************
* Function Name  : MsgVersion
* Description    : Display the current CircleOS version and the version needed
*                  exit to main menu after 4 secondes
*
* Input          : None
* Return         : MENU_REFRESH
*******************************************************************************/
static enum MENU_code MsgVersion(void)
   {
   int hh,mm,ss,ss2;
   
   DRAW_DisplayString(5,60,"CircleOS",17);
   DRAW_DisplayString(80,60,UTIL_GetVersion(),6);
   DRAW_DisplayString(5,34,NEEDEDVERSION,6);
   DRAW_DisplayString(50,34," required",12);
   
   RTC_GetTime( &hh, &mm, &ss);
   ss = ss + 4;                  // 4 secondes
   ss = ss%60;
   
   do
        {
        RTC_GetTime( &hh, &mm, &ss2 );
        }
   while ( ss2 != ss );           // do while < 4 secondes
   
   DRAW_Clear();
   return MENU_REFRESH;
   }


void RCC_Config(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
 
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
}

void USART_Config(void)
{
    /* Enable GPIOx clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    /* Enable USART2 clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);   

    GPIO_InitTypeDef GPIO_InitStructure;
    /* Configure USART2 Tx (PA.2) as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure USART2 Rx as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);


    /* USART2 configuration ------------------------------------------------------*/
    /* USART2 configured as follow:
        - BaudRate = 9600 baud 
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
        - USART Clock disabled
        - USART CPOL: Clock is active low
        - USART CPHA: Data is captured on the second edge
        - USART LastBit: The clock pulse of the last data bit is not output to
                         the SCLK pin
    */

   
    /* USART configuration ------------------------------------------------------*/

    USART_InitStructure.USART_BaudRate = 9600;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No ;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART2, &USART_InitStructure);

    /* Configure USART2 */
    USART_Init(USART2, &USART_InitStructure);
   
    /* Enable USART2 Receive and Transmit interrupts */
    //USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
 
    /* Enable the USART2 */
    USART_Cmd(USART2, ENABLE);

    //OldHandler = (tHandler)UTIL_GetIrqHandler( 0xD8 );
    //UTIL_SetIrqHandler(0xD8, MyUsart2Handler);
  }

void Timer_Init(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel; 
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    /* Enable the TIM4 Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    /* Time base configuration */
    TIM_TimeBaseStructure.TIM_Period = 65535;
    TIM_TimeBaseStructure.TIM_Prescaler = 719;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
    TIM_ARRPreloadConfig(TIM4, ENABLE);
}

void Send_Byte(u8 Txbyte)
{
  USART_SendData(USART2, Txbyte);
  while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
  TIM_SetCounter(TIM4, 0);
  while (TIM_GetCounter(TIM4)<7);
}

Offline

 

  • Index
  •  » STM32 primer
  •  » Can not detect USART 2 signal at Extension Connector with Oscilloscope

Board footer