Hello,
Currently I am developing a student project where I want to communicate a microcontroller with a computer in wireless way. I chose the PIC18F4550 because is the microcontroller I am most familiar with and to make the wireless communication I chose the bluetooth module HC-06.
But I found what I did isn't working so I decided to fractionate and test it. I tested the physical scheme (which I also uploaded the file with PIC18F4550 datasheet and HC-06 datasheet) and seems like there's no problem with it.
Fig: schematic
Anyway when I simplified the microcontroller code (I'm using C language) to make some tests I found out nothing is being sent to the computer. So I think the main problem is with my code.
I feed the bluetooth module (with 5V, it can be powered from 3.3V to 6V) and got its signal with the computer so I checked its properties and it seems like it's all matching with the properties I configured in the code (9600 bps, etc.).
I only want to do a constant serial transmission and to begin with I want to just send a character to computer as a test. It's my first time working with the usart.h library though and I'm not getting what I am doing wrong.
I read that it'll send the character/string in ASCII code so I put the value of p as 0x31 (1 in ASCII) but I'm not sure if I already have to put it in ASCII values. Also I don't know if I'm using the putrsUSART command in the right way. I chose this command because lately I will need to transmit a string but I already tested my code with putcUSART, putsUSART and WriteUSART but nothing worked.
I am very lost so I would be very thankful if someone can help me with this, please.
Currently I am developing a student project where I want to communicate a microcontroller with a computer in wireless way. I chose the PIC18F4550 because is the microcontroller I am most familiar with and to make the wireless communication I chose the bluetooth module HC-06.
But I found what I did isn't working so I decided to fractionate and test it. I tested the physical scheme (which I also uploaded the file with PIC18F4550 datasheet and HC-06 datasheet) and seems like there's no problem with it.
Fig: schematic
Anyway when I simplified the microcontroller code (I'm using C language) to make some tests I found out nothing is being sent to the computer. So I think the main problem is with my code.
Code:
//Libraries inclusion
#include <xc.h>
#include <usart.h>
//Configurations
#pragma config PLLDIV = 5 //PLL to 20MHz
#pragma config CPUDIV = OSC1_PLL2 //PLL off
#pragma config FOSC = HS //High speed oscillator - 20MHz
#pragma config WDT = OFF //Watchdog off
#pragma config PBADEN = OFF //PORTB begins as digital
#pragma config LVP = OFF //Low voltage record off
#pragma config DEBUG = OFF //Debug off
#pragma config PWRT = ON //Power-up timer on
#pragma config BOR = ON //Brown-out reset on
#pragma config MCLRE = OFF //Master clear off
#define _XTAL_FREQ 20000000 // Oscillator crystal frequency - 20MHz
#define RXFLAG PIR1bits.RCIF //Arrival of byte by serial flag
#define TXFLAG PIR1bits.TXIF // TXREG empty flag
#define BAUDRATE 9600
//Usart initiation function
void usart_init(void)
{
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_BRGH_HIGH,25); //9600 baudrate
}
//Main function
void main (void)
{
INTCON = 0;
PORTC = 0;
TRISC = 0xF9; //0b11111001 //RC6 and RC7 as TX and RX
//Serial port inicialization
TXSTA = 0x24; //Asynchronous mode to 8 bits
SPBRG = 129; //Oscillator 20MHz - Baud Rate = 9600bps
RCSTA = 0x90; //Serial transmission on
INTCON2bits.RBPU = 0;
__delay_ms(30);
char p = 0x31;
while (1)
{
usart_init(); //Calls usart initialization function
__delay_ms(10);
putrsUSART(p); //Transmission of string
__delay_ms(10);
}
}
I only want to do a constant serial transmission and to begin with I want to just send a character to computer as a test. It's my first time working with the usart.h library though and I'm not getting what I am doing wrong.
I read that it'll send the character/string in ASCII code so I put the value of p as 0x31 (1 in ASCII) but I'm not sure if I already have to put it in ASCII values. Also I don't know if I'm using the putrsUSART command in the right way. I chose this command because lately I will need to transmit a string but I already tested my code with putcUSART, putsUSART and WriteUSART but nothing worked.
I am very lost so I would be very thankful if someone can help me with this, please.
Attachments
-
6.8 MB Views: 19
-
757 KB Views: 114