cancel
Showing results for 
Search instead for 
Did you mean: 

Uart (rs232) communication problem

feres_cherif
Associate II
Posted on April 25, 2013 at 01:30

Hi all,

i am trying to establish UART communication between µc and PC. this is my code:

/* Includes ------------------------------------------------------------------*/
#include ''stm32f10x.h''
#include ''platform_config.h''
/* Private typedef -----------------------------------------------------------*/
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
#define TxBufferSize (countof(TxBuffer))
/* Private macro -------------------------------------------------------------*/
#define countof(a) (sizeof(a) / sizeof(*(a)))
/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitStructure;
uint8_t TxBuffer[] = ''Buffer Send from USARTy to hyperterminal using Flags'';
uint8_t RxBuffer[TxBufferSize];
__IO uint8_t TxCounter = 0, RxCounter = 0; 
volatile TestStatus TransferStatus = FAILED; 
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
__IO uint8_t index = 0;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured, 
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/ 
/* System Clocks Configuration */
RCC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* USARTy and USARTz configuration ------------------------------------------------------*/
/* USARTy and USARTz configured as follow:
- BaudRate = 230400 baud 
- Word Length = 8 Bits
- One Stop Bit
- Even parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USARTy */
USART_Init(USART1, &USART_InitStructure);
/* Enable the USARTy */
USART_Cmd(USART1, ENABLE);
while(TxCounter < TxBufferSize)
{ 
/* Send one byte from USARTy to USARTz */
USART_SendData(USART1, TxBuffer[TxCounter++]);
/* Loop until USARTy DR register is empty */ 
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
} 
while (1)
{
}
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval None
*/
void RCC_Configuration(void)
{ 
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA| RCC_APB2Periph_AFIO, ENABLE);
/* Enable USARTy Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); 
}
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USARTy Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/**
* @brief Compares two buffers.
* @param pBuffer1, pBuffer2: buffers to be compared.
* @param BufferLength: buffer's length
* @retval PASSED: pBuffer1 identical to pBuffer2
* FAILED: pBuffer1 differs from pBuffer2
*/
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while(BufferLength--)
{
if(*pBuffer1 != *pBuffer2)
{
return FAILED;
}
pBuffer1++;
pBuffer2++;
}
return PASSED; 
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{ 
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/ 
/**
* @}
*/ 
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

when i try to load it an error message is shown:''CORE NOT HALTED''. i don't know where is the problem.
8 REPLIES 8
Posted on April 25, 2013 at 01:59

Yeah, I have no idea what's going on with your tool chain and debugger, not much detail to work with. Failure of JTAG tools to stop/access the core can be because the core is not powered, in a low power mode, user code has reconfigured pins or is in a WFI loop, or a host of other reasons. If you suspect user code, then reset the device with BOOT0 High. Make sure to use the correct mode SWD or JTAG to communicate with your device/debugger.

Your code as a few issues.

The GPIO pins are not configured correctly. The Tx pin needs to be in AF Mode, and an output.

For 8-bit + Parity you'll need to select 9b mode.

You should really front test TXE before the SendData
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 25, 2013 at 02:07

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20simulator%20STM32f1xx%20discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=517]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUSART%20simulator%20STM32f1xx%20discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=517

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feres_cherif
Associate II
Posted on April 25, 2013 at 02:40

i am using keil µ vision and st link debugger. i am using max232 as ttl converter .

 

dthedens23
Associate II
Posted on April 25, 2013 at 17:29

MAX323 may not work because it is a 5V part.   Use MAX3232 which is a 3V part.

Posted on April 25, 2013 at 18:49

Not sure that addresses the CORE NOT HALTED, which seems pretty much unrelated to the serial coms unless there is an issue with voltages from the MAX232 driving into the STM32 incorrectly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feres_cherif
Associate II
Posted on April 26, 2013 at 12:27

So stm32 doesn't work with max232?

Posted on April 26, 2013 at 13:39

It needs a MAX232 type device capable of running from 3-3.3V and generating RS232 signaling voltages. My concern above was that you had the pins wired appropriately, and if that caused the core error, which otherwise seems unrelated.

ST3241EB

http://www.st.com/web/catalog/sense_power/FM1968/CL1179/SC392/PF66121?referrer=70071840

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dthedens23
Associate II
Posted on April 26, 2013 at 16:11

It is simpler to use a 3.3V MAX3232 rather than a 5v MAX232 in 3.3V microcontrollers.

they are pin for pin compatible and cost the same or even less.

If you absolutely must use a 5V MAX323 then you have to be very careful.

you have to power the MAX323 at 5V.  Do you have a 5V supply on board?

You have to look at the STM32F10X data sheet and use UART pins that are marked ''FT'' (for 5v tolerant).

why don't you specify exactly which UART ports on exactly which STM32F10x and the exact part number of the MAX323?

if you are not careful, then you risk damage to the STM32F10x.