Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include "stm32f4xx.h"
- void Delay(__IO uint32_t nCount) {
- while(nCount--) {
- }
- }
- void initUSART6()
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStruct;
- USART_StructInit(&USART_InitStruct);
- //USART_InitStruct.USART_BaudRate = 115200;
- // The following line works and produces the targeted baud rate of 115200kbps
- USART_InitStruct.USART_BaudRate = 115200 / 3;
- /* Enable GPIO clock */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
- /* Connect PXx to USARTx_Tx*/
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
- /* Connect PXx to USARTx_Rx*/
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
- /* 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(GPIOC, &GPIO_InitStructure);
- /* Configure USART Rx as alternate function */
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- /* USART configuration */
- USART_Init(USART6, &USART_InitStruct);
- /* Enable USART */
- USART_Cmd(USART6, ENABLE);
- }
- void myPrint(uint8_t *msg, uint16_t len) {
- uint16_t n;
- for (n = 0; n < len; n++) {
- while (USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET) {}
- USART_SendData(USART6, *(msg++));
- }
- }
- int main(void)
- {
- uint32_t cnt = 0;
- uint8_t *msg = "hello world\r\n";
- initUSART6();
- while(1) {
- // Delay(100L);
- myPrint(msg, strlen(msg));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement