İyi günler,
Kodlamada çok yeniyim discovery kiti üzerinde çalışmalar yapmaya çabalıyorum. internette bir kod buldum. ve bunu stm32f4 e uyarlamam gerekiyor.Staj yaptığım yerde buna benzer bir şey yapmam gerekiyor ve internetteki bilgiler arasında gerçekten kayboldum. Acaba yardımcı olabilir misiniz?
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "misc.h"
int i;
//ErrorStatus HSEStartUpStatus;
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void USART1_IRQHandler(void);
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
int main(void)
{
usart_rxtx();
while(1)
{
}
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/******************************************************************************/
/**
* @brief This function handles USARTx global interrupt request
* @param None
* @retval None
*/
void USART1_IRQHandler(void)
{
if ((USART1->SR & USART_FLAG_RXNE) != (u16)RESET)
{
i = USART_ReceiveData(USART1);
if(i == '1'){
GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_SET); // Set '1' on PA8
UARTSend("LED ON\r\n",sizeof("LED ON\r\n")); // Send message to UART1
}
else if(i == '0'){
GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_RESET); // Set '0' on PA8
UARTSend("LED OFF\r\n",sizeof("LED OFF\r\n"));
}
}
}
void usart_rxtx(void)
{
const unsigned char welcome_str[] = " Welcome to Bluetooth!\r\n";
/* Enable USART1 and GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* NVIC Configuration */
NVIC_Configuration();
/* Configure the GPIOs */
GPIO_Configuration();
/* Configure the USART1 */
USART_Configuration();
/* Enable the USART1 Receive interrupt: this interrupt is generated when the
USART1 receive data register is not empty */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* print welcome information */
UARTSend(welcome_str, sizeof(welcome_str));
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure (PA.8) as output */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure); // Save
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : USART_Configuration
* Description : Configures the USART1
*******************************************************************************/
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART1 configuration ------------------------------------------------------*/
USART_InitStructure.USART_BaudRate = 9600; // Baud Rate
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);
/* Enable USART1 */
USART_Cmd(USART1, ENABLE);
}
/**
* @brief Configures the nested vectored interrupt controller.
* @param None
* @retval None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
* Function Name : UARTSend
* Description : Send a string to the UART.
* Input : - pucBuffer: buffers to be printed.
* : - ulCount : buffer's length
*******************************************************************************/
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
USART_SendData(USART1, (uint16_t) *pucBuffer++);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{
}
}
}
Mesajlarınıza kod eklemek için "KOD" butonunu
kullanınız.
https://www.picproje.org/index.php/topic,70550.msg541354.html#msg541354
Ayrıca;
F.K. 2-c ve 2-ç maddelerine dikkat edip yeniden düzenleme
yapınız.
https://www.picproje.org/index.php/topic,65932.0.html
EK :
Kalın (Bold) olarak yazılan kısmı da normal hale getiriniz...