I'm trying to send AT commands to HC05 for get other device names and rssi values.I'm using MSP-EXP430G2ET and HC05 module, pin connections are:
MSP HC05
RX(P1.1) TX
TX(P1.2) RX
GND GND
3.3V VCC
EN and STATE pins are empty. (I don't know are theese necessary)
And here is my main file :
#include <msp430.h>
// HC-05 baud rate
#define BAUD_RATE 9600
// Buffer length for UART communication
#define BUFFER_LENGTH 20
// HC-05 UART pins
#define HC05_TX BIT1
#define HC05_RX BIT2
// Delay function
void delay(unsigned int d) {
volatile unsigned int i;
for(i=0; i<d; i++);
}
// Initialize UART
void uart_init() {
P1SEL |= HC05_TX + HC05_RX;
P1SEL2 |= HC05_TX + HC05_RX;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104;
UCA0BR1 = 0;
UCA0MCTL = UCBRS0;
UCA0CTL1 &= ~UCSWRST;
}
// Send a character through UART
void uart_send_char(char c) {
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = c;
}
// Send a string through UART
void uart_send_string(char* str) {
int i;
for(i=0; str[i]!=0; i++) {
uart_send_char(str[i]);
}
}
// Receive a character through UART
char uart_receive_char() {
while(!(IFG2 & UCA0RXIFG));
return UCA0RXBUF;
}
// Receive a string through UART
void uart_receive_string(char* buffer) {
int i;
for(i=0; i<BUFFER_LENGTH; i++) {
buffer[i] = uart_receive_char();
if(buffer[i] == '\r') {
break;
}
}
buffer[i] = 0;
}
// Send an AT command and wait for response
void hc05_send_at_command(char* command, char* response) {
char buffer[BUFFER_LENGTH];
int i;
uart_send_string(command);
delay(100000);
uart_receive_string(buffer);
for(i=0; buffer[i]!=0; i++) {
response[i] = buffer[i];
}
response[i] = 0;
}
int main(void) {
WDTCTL = WDTPW + WDTHOLD;
uart_init();
char response[BUFFER_LENGTH];
// Send AT command to HC-05 and wait for response
hc05_send_at_command("AT\r\n", response);
// Print response
uart_send_string("Response: ");
uart_send_string(response);
while(1);
return 0;
}
I asked Chat GPT to write this, it looks correct to me but when i open terminal screen in Code Composer Studio there is nothing happens. Should I use USB-TTL Converter ?
I tried connect EN pin to 3.3V (Nothing changed so I cut that connection). open a PuTTY terminal but nothing changed again.