Работаем с labview на примере stm32
Работаем с labview на примере stm32
Сообщение Rogers » 16 окт 2014, 15:02
#include «stm32f4xx.h»
#include «stm32f4xx_gpio.h»
#include «stm32f4xx_rcc.h»
#include «stm32f4xx_usart.h»
char uart2_rx_buf[128];
uint8_t uart2_rx_bit;
void send_to_uart(uint8_t data)
<
while(!(USART2->SR & USART_SR_TC));
USART2->DR=data;
>
//
void send_str(char * string)
<
uint8_t i=0;
while(string[i])
<
send_to_uart(string[i]);
i++;
>
>
//USART2
void usart_init(void)
<
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); //PA3 k TX USART2
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); // PA2 k RX USART2
//TX UART
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);
// RX UART
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
int my_atoi(char a[]) <
int c, sign, offset, n;
for (c = offset; a[c] != ‘