Jmod-BT-1을 이용해 윈도우 PC와 통신하기
2019. 8. 24. 13:19ㆍ임베디드/ATmega128
AT 명령어를 이용해서 Jmod-BT-1 셋업을 완료했다면, 윈도우 PC 블루투스 동글과 연결하여 기존 usb-to-UART를 대체하려고 한다. 블루투스 전원을 올바르게 연결했다면, 윈도우 PC에 블루투스 목록이 뜰 것이다. 이후 설정한 비밀번호를 입력하면 페어링이 완료된다. 비밀번호 설정을 하지 않았다면 디폴트로 설정된 1234를 입력하면 된다

그리고 장치관리자로 가서 몇번의 COM 포트와 연결되었는지 확인한다

총 2개가 확인되는데 둘 중 하나에 잡히게 되는데, 현재는 COM11에 잡혀있다. 외부에서는 블루투스 통신 방식으로 하고 내부에서는 UART로 나가면서 처리되기 때문에, 기존 UART 코드를 포트 번호만 바꿔서 넣어주면 된다
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* uart.c | |
* | |
* Created: 2019-04-29 오후 7:27:25 | |
* Author: yeong | |
*/ | |
#include "uart.h" | |
FILE OUTPUT = FDEV_SETUP_STREAM(uart1_trasnmit, NULL, _FDEV_SETUP_WRITE); | |
FILE INPUT = FDEV_SETUP_STREAM(NULL, uart1_receive, _FDEV_SETUP_READ); | |
volatile int flag; | |
volatile int rxdata; | |
ISR(USART1_RX_vect) { | |
unsigned char tmp = UDR1; | |
if(tmp >= '0' && tmp <= '9') { | |
if(flag) { | |
rxdata = rxdata * 10 + tmp - '0'; | |
} | |
else { | |
rxdata = tmp - '0'; | |
flag = 1; | |
} | |
} | |
else if(tmp == '\r') { | |
flag = 0; | |
} | |
} | |
void uart1_init(void) { | |
UBRR1H = 0x00; | |
UBRR1L = 16; | |
UCSR1A |= (1<<U2X1); | |
UCSR1C |= 0x06; | |
UCSR1B |= (1<<RXEN1) | (1<<TXEN1); | |
stdin = &INPUT; | |
stdout = &OUTPUT; | |
} | |
void uart1_trasnmit(char data) { | |
while(!(UCSR1A & (1 << UDRE1))); | |
UDR1 = data; | |
} | |
unsigned char uart1_receive(void) { | |
while(!(UCSR1A & (1 << RXC1))); | |
return UDR1; | |
} | |
void uart1_rx_int_init(void) { | |
UCSR1B |= (1 << RXCIE1); | |
sei(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* jmodbt_uart.c | |
* | |
* Created: 2019-08-24 오후 12:53:19 | |
* Author : yeong | |
*/ | |
#define F_CPU 16000000UL | |
#include <util/delay.h> | |
#include <avr/io.h> | |
#include "uart.h" | |
int main(void) | |
{ | |
uart1_init(); | |
/* Replace with your application code */ | |
while (1) | |
{ | |
printf("hello ble!\r\n"); | |
_delay_ms(300); | |
} | |
} |

'임베디드 > ATmega128' 카테고리의 다른 글
unsigned간 연산 (0) | 2019.08.24 |
---|---|
ATmega128 HR-SR04 초음파 센서 제어하기 - 2 (0) | 2019.08.24 |
Jmod-BT-1(HC05 기반) 셋업 설정 (0) | 2019.08.24 |
ATmega128 HR-SR04 초음파 센서 제어하기 - 1 (4) | 2019.08.24 |
ATmega128 I2C 1602 텍스트 LCD 사용자 정의 문자 생성(CGRAM) (0) | 2019.08.15 |