cancel
Showing results for 
Search instead for 
Did you mean: 

Discover Wi-Fi with stm32f407 UART Problem

manjae
Associate II
Posted on February 24, 2016 at 11:12

I have difficulty handling Discover Wi-Fi. 

Currently, I am using keil vision and stm32f407 as a host mcu device Also, I am trying to modify the example code but it is not working well. 

I need help and advice. In the example, PB6 and PB7 are used to communicate with host mcu. 

Unfortunately, I have already assigned these pins to the another function. 

So I changed and tried several times such as UART1 to UART2, UART1 to UART3 and UART1 to UART1(PA9,PA10).

Surprisingly, It is only operated in PB6,PB7.... Does anybody know what happen in here and how to change it?

I tried the EWW website and others... it did not work.. I am really looking forward to meeting your answer. 

Thanks

11 REPLIES 11
Posted on February 24, 2016 at 11:30

Electrons only go where the wires are attached.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
manjae
Associate II
Posted on February 24, 2016 at 15:11

I wired every time when I change the other UART.

For instance, When I use UART2,  I connect PA2 and PA3 with the wifi module.

But It did not work.  

Could you give me a help?

Posted on February 24, 2016 at 17:23

I don't have this board, or the software you are trying to compile and use.

You'll will need to present your problem in a manner that can be reviewed and understood. Showing the code and circuit diagram is more usable than prose describing things.

The USART clocks and configuration must be correct. The pin assignments and AF mux settings must be correct.

Diagram how you have things connected, and what else is connected to the DISCO.

Get a scope and determine what signals you can see, and refine ''not working'' into a more specific description of what is happening, and what is expected. Do this at the pin level, not from a system overview level.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
manjae
Associate II
Posted on February 25, 2016 at 07:36

Firstly, Thanks for reply.

-For the software

I changed below code. Below code is given and I changed USART1 --> USART2

and pin assignment are changed to PA2 as a Tx and PA3 as a RX.

Also UART CLOCK is changed APB2 --> APB1.

-For the hardware

I wired PA2 with SN8200 RX pin and PA3 with SN8200 TXpin

P.S.

Because I am out of offices I will scope as your recommendation.

Thanks

************code******************

void SN8200_HAL_Init(uint32_t baudrate)

{

    GPIO_InitTypeDef GPIO_InitStructure;

    USART_InitTypeDef USART_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable GPIO clock */

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    /* Enable UART clock */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    /* Connect PXx to USARTx_Tx*/

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);

    /* Connect PXx to USARTx_Rx*/

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);

    /* Configure USART Tx as alternate function  */

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* Configure USART Rx as alternate function  */

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

    /* Enable the USART1 Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    /* USART configuration */

    USART_InitStructure.USART_BaudRate = baudrate;

    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(USART1, &USART_InitStructure);

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    /* Enable USART */

    USART_Cmd(USART1, ENABLE);

}

void SN8200_HAL_SendData(unsigned char *buf, int len)

{

    int i;

    for (i = 0; i < len; i++) {

        USART_SendData(USART1, buf[i]);

        while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);

    }

}

bool SN8200_HAL_RxBufferEmpty(void)

{

    return (RxBufferHead == RxBufferTail);

}

uint8_t SN8200_HAL_ReadByte(void)

{

    uint8_t data = 0;

    if(RxBufferHead != RxBufferTail) {

        data = RxBuffer[RxBufferTail];

        RxBufferTail = (RxBufferTail + 1) % RX_BUFFER_SIZE;

    }

    return data;

}

void USART1_IRQHandler(void)

{

    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {

        RxBuffer[RxBufferHead] = USART_ReceiveData(USART1);

        RxBufferHead = (RxBufferHead + 1) % RX_BUFFER_SIZE;

    }

}

manjae
Associate II
Posted on February 26, 2016 at 09:25

@Clive1

Hello,

I did what you recommend and I found one problem.

A problem is that Tx pin is not changed even if I changed it code well.

1. Given example , Tx, Rx are assigned PB6,PB7 respectively.

2. I changed it to UART2 and Tx, Rx are assigned PA2,PA3 respectively and wiring is also well.

3. I scope PA2 and PA3 then, PA3 state is high butt PA1 is low.

 and I also scope to UART1 which are PB6 and PB7. PB6 is still high and PB7 is low.

Summary: Only UART Tx is not changed...

Could you give me advice and share your idea with me?

It would be very helpful

Thanks  

AvaTar
Lead
Posted on February 26, 2016 at 10:50

For changing UART <A> at pins <a1>/<a2> to UART <B> at <b1>/<b2>, check that you:

  •  - changed the RCC clock enable for UART <A> to UART <B>
  •  - changed the RCC clock enable for GPIO <a> to GPIO <b>
  •  - changed the GPIO pin config from <a1>/<a2> to <b1>/<b2>
  •  - changed the GPIO port in the GPIO_Init() call to the proper port of <b1>/<b2>
  •  - changed the USART_Init() and USART_ClockInit() calls from <A> to <B>
  •  - changed all USART_Cmd() calls from <A> to <B>
and, when using interrupts, configured and implemented the proper interrupt handler for UART <B>.

manjae
Associate II
Posted on February 26, 2016 at 12:46

@AvarTar

I have already checked several times as you recommendation.

Below code was changed and that is all what I changed but it did not work. 

void SN8200_HAL_Init(uint32_t baudrate)

{

    GPIO_InitTypeDef GPIO_InitStructure;

    USART_InitTypeDef USART_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable GPIO clock */

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    /* Enable UART clock */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    /* Connect PXx to USARTx_Tx*/

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

    /* Connect PXx to USARTx_Rx*/

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);

    /* Configure USART Tx as alternate function  */

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure USART Rx as alternate function  */

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

    /* Enable the USART2 Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    /* USART configuration */

    USART_InitStructure.USART_BaudRate = baudrate;

    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);

    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

    /* Enable USART */

    USART_Cmd(USART2, ENABLE);

}

void SN8200_HAL_SendData(unsigned char *buf, int len)

{

    int i;

    for (i = 0; i < len; i++) {

        USART_SendData(USART2, buf[i]);

        while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);

    }

}

bool SN8200_HAL_RxBufferEmpty(void)

{

    return (RxBufferHead == RxBufferTail);

}

uint8_t SN8200_HAL_ReadByte(void)

{

    uint8_t data = 0;

    if(RxBufferHead != RxBufferTail) {

        data = RxBuffer[RxBufferTail];

        RxBufferTail = (RxBufferTail + 1) % RX_BUFFER_SIZE;

    }

    return data;

}

void USART2_IRQHandler(void)

{

    if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {

        RxBuffer[RxBufferHead] = USART_ReceiveData(USART2);

        RxBufferHead = (RxBufferHead + 1) % RX_BUFFER_SIZE;

    }

}

AvaTar
Lead
Posted on February 27, 2016 at 14:04

Here an example for UART3, that works for me:

/* Initialize the USART3 (CMD_BAUDRATE,8,n,1,none) command interface
* PD8 => usart3.TX
* PD9 => usart3.RX
* these pins are available on the F4 Discovery board
*/
void initUART (void)
{
uint32_t sendBytes;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART3, ENABLE); // configure clock for USART
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE); // configure clock for GPIO
GPIO_PinAFConfig (GPIOD, GPIO_PinSource8, GPIO_AF_USART3); // configure AF
GPIO_PinAFConfig (GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = DATA_BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init (USART3, &USART_InitStructure);
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit (USART3, &USART_ClockInitStructure);
USART_Cmd (USART3, ENABLE);
/* parametrize USART3-Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init (&NVIC_InitStructure);
/* Interrupt at reception and receive errors */
USART_ITConfig (USART3, USART_IT_RXNE, ENABLE);
USART_ITConfig (USART3, USART_IT_ERR, ENABLE);
}

Of course you don't the error interrupts, if you are not willing to handle them. As suggested in other threads, connect RX and TX of the UART directly, and check if you receive the characters you transmit. If that works, your initialization is o.k., and you can go on to check the hardware to your WiFi adapter.
manjae
Associate II
Posted on March 02, 2016 at 08:14

I am afraid of that I tell you this.

The ST32F407 is also working very well with PC.

Any UART communication is working well with PC.

Only I struggle that is UART between STM32 and SN8200(WIFI).

Is it possible that SN8200 is only working UART1 with STM32?