/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Question: USART2 on Primer1

Username:     
Password:     
             

Forum

# 1   2009-06-23 12:50:47 Question: USART2 on Primer1

Mysterio
Member
From: Germany/NRW
Registered: 2009-05-22
Posts: 23

Question: USART2 on Primer1

Hello,

I want to enable the USART2 connections on the pad J1 backside of the primer1 (see the pdf-file of the primer1 schematics for detailed information), because I want to connect a serial-slot (RS232) on it. What have I to do in my program to make this possible?

(by the way: my OS-Version is 1.7)

I tryed it with some commands from "stm32f10x_usart.c"
I think that the commands are right but on the wrong place in my program (or maybe something is missing)
I used the commands:

USART_InitTypeDef USART2_Init;
USART_ClockInitTypeDef USART2_ClockInit;

USART_StructInit(&USART2_Init);
USART_ClockStructInit(&USART2_ClockInit);
USART_ClockInit(USART2, &USART2_ClockInit);
USART_Init (USART2, &USART2_Init);
USART_Cmd(USART2, ENABLE);

The program runs correctly, it just dosn't enable the USART connections on the pad.
In the end I want to be able to send and recieve data over the RS232 (Rx/Tx).

Need help, please...

Last edited by Mysterio (2009-06-24 08:33:11)


The only definitly knowledge we have, is that we don't know anything. -Sokrates-

Offline

 

# 2   2009-06-25 11:05:57 Question: USART2 on Primer1

Mysterio
Member
From: Germany/NRW
Registered: 2009-05-22
Posts: 23

Re: Question: USART2 on Primer1

Ah sorry,

I fixed my problem, now USART2 works, but not like it should work...
I want on HyperTerminal the output "ABCDEFG...." but it shows "PNNNNNNNN..."

I think my Bautrate is correct...

What made I wrong???

Here is the code:

(By the way: This programm has its origin from the "toggle_with_circleOS" example-project)

char msg [15];
static int CurrentLedMode = LED_OFF;
static int toggle_count=0;
int i;
int zbs;

void InitUSART()
{
USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;


      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
      /* Enable USART2 clocks */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
    /* Enable the USART2 Interrupt */
      NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_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 (PA.3) 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_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);

  /* Enable the USART2 */
  USART_Cmd(USART2, ENABLE);
}

u16 uartv;
enum MENU_code Application_Handler(void)

{

zbs = 0;

if (zbs==0)
{
    BUTTON_SetMode  ( BUTTON_ONOFF);

    InitUSART();

   

    zbs = 1;
}
        if (zbs == 1)
        {
        LCD_SetBackLight(0x8000);
        UTIL_SetPll(SPEED_VERY_HIGH);
       
        toggle_count++;
        USART_SendData(USART2, 'a'+(toggle_count%26));
       
             if (toggle_count >= MAX_TOGGLE_COUNT)
             {
     
                BUTTON_SetMode  ( BUTTON_ONOFF);
                toggle_count=0;
                toggle_count++;
                CurrentLedMode = (CurrentLedMode == LED_ON) ? LED_OFF : LED_ON;
   
                LED_Set ( LED_GREEN,CurrentLedMode);
                LED_Set ( LED_RED,!CurrentLedMode);
                BUZZER_SetMode(BUZZER_SHORTBEEP);
                LCD_SetBackLightOn();
               
              if (  BUTTON_GetState() == BUTTON_PUSHED )
                    {
                    LCD_SetBackLight(0x8000);
                    LED_Set ( LED_GREEN,LED_ON);
                    LED_Set ( LED_RED,LED_OFF);
                    BUZZER_SetMode (BUZZER_OFF) ;
                    DRAW_Clear();
                   
                    for( i = 0; i < 100; i++)
                         {
                               
                                sprintf(msg,"%d", i);
                                DRAW_DisplayString( 112, 118, msg, 4); // X, Y, string, length
                               
                         }
 
                     
                   
                    }   
              }
         
          }
               
   
       
       
       
        if (zbs == 0)
        {
        DRAW_Clear();
        UTIL_SetPll(SPEED_VERY_LOW);
        LCD_SetBackLight(0x1000);
       
        if (  BUTTON_GetState() == BUTTON_PUSHED )
            {
            LED_Set ( LED_GREEN,LED_ON);
            LED_Set ( LED_RED,LED_OFF);
            DRAW_SetCharMagniCoeff(1);
            LCD_SetBackLightOn();
            DRAW_Clear();
            UTIL_SetPll(SPEED_VERY_LOW);
            LCD_SetBackLight(0x1000);
           
            return MENU_Quit(); 
            }
        }
   
        return MENU_CONTINUE;
}

Can anyone help me?


Thanks

Last edited by Mysterio (2009-06-25 11:12:25)


The only definitly knowledge we have, is that we don't know anything. -Sokrates-

Offline

 

# 3   2009-06-26 14:05:21 Question: USART2 on Primer1

Mysterio
Member
From: Germany/NRW
Registered: 2009-05-22
Posts: 23

Re: Question: USART2 on Primer1

Now I changed the code at the following point:

  toggle_count++;
        USART_SendData(USART2, 'a'+(toggle_count%26));

to:

//u16 uartv;
u16 temp;

enum MENU_code Application_Handler(void)
{
InitUSART();
zbs = 0;

if (zbs==0)
{
    BUTTON_SetMode  ( BUTTON_ONOFF);

    //uartv = USART_ReceiveData(USART2);

    zbs = 1;
}
        if (zbs == 1)
        {
        LCD_SetBackLight(0x8000);
        UTIL_SetPll(SPEED_VERY_HIGH);
       
        toggle_count++;
        temp = 'a'+(zaehler%26);
        USART_SendData(USART2, temp);
        zaehler++;
        .
        .
        .

now appeares on Hyperterminal:

K%JI$HG#FE"C!O'NM&L      K%J....

instead of the wantet alphabet...

Can anybody help me?

I tried a lot of different possibilities but nothing helped.
That's driving me crazy and I don't know anymore ways to get this fixed.

I really need help, please...

Last edited by Mysterio (2009-06-29 13:14:55)


The only definitly knowledge we have, is that we don't know anything. -Sokrates-

Offline

 

# 4   2009-06-27 09:24:09 Question: USART2 on Primer1

manfred180467
New member
Registered: 2009-06-04
Posts: 1

Re: Question: USART2 on Primer1

Offline

 

# 5   2009-06-29 06:47:44 Question: USART2 on Primer1

Mysterio
Member
From: Germany/NRW
Registered: 2009-05-22
Posts: 23

Re: Question: USART2 on Primer1

Manfred,

I tried that and nothing changed. There is still this strange output on HyperTerminal.

anyway, thanks for your help...

Last edited by Mysterio (2009-06-29 07:20:15)


The only definitly knowledge we have, is that we don't know anything. -Sokrates-

Offline

 

# 6   2009-07-10 09:25:06 Question: USART2 on Primer1

domen
Member
Registered: 2008-10-27
Posts: 10

Re: Question: USART2 on Primer1

You need to recompile FWLib with the correct HSE_Value (12000000 for primer1, default compiled is 8 - alternative would be to change baudrate to *2/3)

Or maybe it's grounding problem.

Last edited by domen (2009-07-10 09:29:11)

Offline

 

# 7   2009-07-10 09:53:54 Question: USART2 on Primer1

Mysterio
Member
From: Germany/NRW
Registered: 2009-05-22
Posts: 23

Re: Question: USART2 on Primer1

The HSE Value was already set to 12000000...

But it's possible, that I made a mistake in my application-structure...

Either a logic-mistake (for example: a loop on the wrong place in my application), or some missing configuration-commands


The only definitly knowledge we have, is that we don't know anything. -Sokrates-

Offline

 

Board footer