Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f886 uart + AT problem

Status
Not open for further replies.

micheadache

New Member
hi experts around, i am currently using PIC16f886, pickit2, MPlab for a project.
i editted the codes i obtained from the sample codes taken from the HiTechC folders.
but how do i show that the connectionis working?
can i know where will the "A" be displayed at? how do we actually do that?

alternatively, i found another shorter & simpler codes done by a fellow expert in this forum, https://www.electro-tech-online.com/threads/hi-tech-c.87896/ through his link of "**broken link removed**". however, i didnt get anything as the output

pls help me as this project is really crucial to me and am rather clueless/confused of my next step. solving this current problem of mine is an intermediate step to go to the next step - configuring AT commands for the p16f886 and rs232 and BT module
 
Dont forget when interfacing with a RS232 / PC interface you will need a MAX232 converter chip (or something which can do 232 level shifting).

Wilksey
 
i actually have a DIY max232 on hand.
no idea of the codings and how to communicate between p16f886 and pc via HT. thats the first task that i have to complete before moving on to the next stage (progamming the UART, program the receiving portion, program the AT command to enable the p16f886 to be bluetooth compatible)

hope i can get some help here..would really appreciate it.
 
a DIY max232? the old transistor trick by chance?

So, what exactly are you trying to achieve?

Are you asking for code to read / write from the UART on the PIC to a PC?

Wilksey
 
yup, a DIY max232. i got it from my supervisor. seems to be working well when i used it to try the bluetooth communication.

that aside, i am currently trying to transmit data to PC (viewed via TeraTerm or Hyper Terminal), via microp (P16F886).
i initialised all the EUSART platform and sended 0x41 and 0x31, 'A' and '1' on e ASCII table respectively. I tried probing it with a oscillope but the 1s and 0s are there correctly. Hoever, the words dont seem to be coming out well in the PC. nto sure wats the problem, is it due to the oscillator or baud rate? i am using Fosc 8Mhz, BR 9600, SPBRG 51.

This is just my first task =( following which, i have to configure my bluetooth modules with the use of AT commands thru the 16F886 too.
 
I see,

The BRGH would have to be set to 1 for SPBRG to be 51, else it is 12 for BRGH = 0. Something to check.

You would be better off posting your current code, along with the name of the compiler you are using.

Sounds like a fairly straight forward request, so long as your DIY 232 chip has the correct voltage shifts.

Put the code in the [ code ] [ /code ] tags to retain formatting.

Also, if you can list the AT commands needed to configure the BT module, may be able to incorporate some of that into the code.

Wilksey
 
yup, i have set BRGH to 1 and BRG16 = 0

however, now, i am trying to firgure out if the diy232 works, cos everything seems right.

will include my codes in for your reference once i tried out the diy 232?

its fairly simple u mean? oh gosh, am clueless
 
am i right to assume using 8Mhz, 9600Baud rate?

the codes that am currently using is the following.
its rather simple i guess. using MpLab PICKIT2.

Code:
	#include<pic.h>
	#include<htc.h>
	#include<conio.h>
	#include<stdio.h>
	
void init_rs232();

void main()
{

	TRISE = 0x08;
	TRISB = 0x00; 
	init_rs232();

		while(1){
			if(RE3==0){
			RB0=1;
			if(TRMT)
				TXREG = 0x41; //sending 'A'
			}
			else{
				RB0=0;
				if(TRMT)
				TXREG = 0x70; //sending 'p'
			}
		}
}

void init_rs232()
{
	BRGH = 1;	 
	BRG16 = 0;
	
	SPBRG = 51;	/* set baud rate: Fosc=8Mhz, 16, BR=9600 */
	TX9  = 0;	/* ninebits?1:0,,,8- or 9-bit transmission */
	SYNC = 0;	/* asynchronous */
	SPEN = 1;	/* enable serial port pins */
	TXEN = 1;	/* enable the transmitter & (automatically)TXIF=1 */
	CREN = 1;	/* enable reception */
	SREN = 0;	/* no effect */
	TXIE = 0;	/* disable tx interrupts */
	RCIE = 0;	/* disable rx interrupts */
	}

i think i should take one step at a time and solve this first before going into the AT commands. am really worried as there's a deadline i need to meet for submission. have many more to go. urgh
 
Last edited:
Since you are using Pickit2, you can use its version of terminal to see the output of your chip on screen, provided you have all set up right.

Go into tools on the Pic2 site and click on USART tool. Since you are using the 16F866, I assume you are using a breadboard or something. Figure out a way of connecting the USART TX and RX pins to the Clk and Data of ICSP. The diagram on the USART screen shows the connection. Make sure the baud rate on the USART tool screen is set, and connect. You should see something to go on. Going this route, you will eliminate the use of R232 and see what is happening. Build in steps.

Your screen might look something like my attachment:
 

Attachments

  • PIC-2-PC art.GIF
    PIC-2-PC art.GIF
    36.9 KB · Views: 393
i am actually using the PicKit2 Demo board from Microchip and i dont think i am allowed to eliminate the use of rs232, as we're supposed to use it to program the bluetooth module into the 16F886 later on.
 
Okay, I see. I did not realize there were stipulations. You still might be able to use the USART tool to help you get started. Luck.
 
I have just compiled and ran your code on a Simulator, with 8mhz clock it constantly sends out "A" across the UART.

What exactly do you get out of your PIC when plugged into the PC? anything at all, or garbage data or another character than expected?

You may also want to draw a simple circuit diagram of your connections.

Wilksey
 
hey Wilksey,

good to have u back here!
u got A as the output at ur side?!?!
i get a continous of other alphabets or digits but never A. i am using Hyper Terminal to see the output


i am actually given this board for my project, pickit 28pin board, MpLab, Pickit2, HyperTerminal & sometimes TeraTerm to see the output into the PC, max232 & rs232 connecting to RC6(Tx), RC7(Rx), Vdd and Gnd of the board
 
Last edited:
The Baud Rate and Fosc and SPBRG are correct as it will output "A" at 9600 at 8MHz, but it is all in the PIC datasheets, along with calcluations etc.

Once you get a stream of "A"s on your terminal you know it is working.
 
Yes I get a stream of "A" output on my side using Hyperterminal.

You could try adding this to your code, below the #include statements:
Code:
	__CONFIG(WDTDIS & XT);

It sounds like a configuration issue or a 232 level converter issue.

Wilksey
 
yes, i have been trying using 9600, 8Mhz,, calculated and referred to the 16f886 datasheet on the values for SPBRG, etc...

Hmm its weird cos i get nothing out of the program after inserting that line below my #include statements and my LED doesnt light up anymore too.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top