12F675 UART Problem

Beta Testing discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
TOPNG
Posts: 4
Joined: 18 Apr 2013 16:46

12F675 UART Problem

#1 Post by TOPNG » 18 Apr 2013 17:05

hi i need help with 12f675 uart it don't work
I wrote a test program to check If I get the right value
So I am sending information I do not get the same information back
the occal : 3464

i add the code + results

the code:
void main() {
//internal oscillator 4Mhz
ansel=0;
cmcon=7;
trisio=2;

// Init 2400baud rate, no parity bit
Soft_Uart_Init(&gpio, 1, 0, 2400, 0);

while (1)
{

DATA = Soft_Uart_Read(&rec); // Receive data

Soft_Uart_Write(DATA); // Send data via UART
}}



the results
TX: 77
RX: 7F
TX: 44 56
RX: 7C 5E
TX: 66 54
RX: 7E 5E
TX: 66 66
RX: 7E 7E
TX: 42 52 33 24 24
RX: 7A 5E 79 1E 3E
TX: 42 52 33 24 24
RX: 7A 5E 79 1E 3E


i dont know what is the problem please help

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: 12F675 UART Problem

#2 Post by marina.petrovic » 19 Apr 2013 13:09

Hi,

Please try to deduce where the problem occurs, when UART sent or receive data?

Try to put in function Soft_Uart_Write() some buffer and look what's happening.

Looking at the part of the code that you sent I can not find the source of the error.

Best regards,
Marina

TOPNG
Posts: 4
Joined: 18 Apr 2013 16:46

Re: 12F675 UART Problem

#3 Post by TOPNG » 19 Apr 2013 15:34

hi Marina
Thank you for your response
the problem in the receiving area .

for exmple i Write this code :

unsigned char rec,DATA;
void main() {

ansel=0;
cmcon=7;
trisio=0b00000010;
// Init (8 bit, 4800 baud rate, no parity bit..)

Soft_Uart_Init(&gpio, 1, 0, 2400, 0);

while (1)
{
DATA = Soft_Uart_Read(&rec); // Receive data
Soft_Uart_Write(DATA); // Send data via UART
if (DATA==(0x88)) gpio.b2=1;
}}//end

whan i send 0x88 the port remains low and whan i send 0x44 the port go high
i plugged logic analyzer in the receiver leg {gp1 in 12f675 tx in computer} and the data is correct
in the transmit {gp0 in 12f675 rx in computer} the data is not the same as i send .
{
I am willing to hear suggestions to solve this problem ?

thanks

TOPNG
Posts: 4
Joined: 18 Apr 2013 16:46

Re: 12F675 UART Problem

#4 Post by TOPNG » 20 Apr 2013 13:00

hi Marina

I think the problem with input information into the system
i hooke an logic analyzer on port 0{rx from computer} and port 1 {tx from computer}.

I wrote the following software
unsigned char rec,DATA;
void main() {
ansel=0;
cmcon=7;
trisio=0b00000010;
// Init (8 bit, 2400 baud rate, no parity bit..)
Soft_Uart_Init(&gpio, 1, 0,2400, 0);
gpio.b2=0;
while (1)
{
DATA = Soft_Uart_Read(&rec); // Receive data
Soft_Uart_Write(DATA); // Send data via UART
if (DATA==0x88) gpio.b2=1;
}}

whan i send 0x88 port gp2 remain low
the logic shows that i send 0x88 and recive 0xf6;
and whan i send 0x44 port gp2 go high
the logic shows that i send 0x44 and recive 0x96;

can i dump the receiving data to internal eeprom or extrnal ?
if so ,it would be nice to have an example code !

Thanks for the help

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: 12F675 UART Problem

#5 Post by marina.petrovic » 22 Apr 2013 15:10

Hi,

Please, check did you set properly COM ports value in Usart Terminal (stop bits, parity, data bits)?
Also, check the settings of the Clock.

In your post I can see that the values are shifted for 1.
It leads me to conclude that the code is okay but something is not set correctly.

You said that you plugged logic analyzer, I do not know does he interprets the data correctly?

Best regards,
Marina

TOPNG
Posts: 4
Joined: 18 Apr 2013 16:46

Re: 12F675 UART Problem

#6 Post by TOPNG » 24 Apr 2013 12:16

hi
i chack and reset the com ports.
also through pickit2 uart it is the same .
also through buspirate uart it is the same .

the rs232 is set as 8bit no parity,no flow control,and stop bit 1.
the occal 3464 // ineed internal oscillator 4mhz

i checked the code in pic12f683 and it work perfectly.
Why it does not work with 12f675 ??

Durango
Posts: 134
Joined: 11 May 2006 17:48
Location: Maryland USA

Re: 12F675 UART Problem

#7 Post by Durango » 24 Apr 2013 14:43

Hi TOPNG,

I believe your problem is the PIC12F675 is not running at 4MHz as you intended it to.

You need to call the factory cal byte located at the end of memory. I do not see this in your posted code so the PIC is running at somewhere near 4MHz but not good enough for communication.

You need to add this at the beginning of your code.

Code: Select all

OSCCAL = OSCCAL 

asm 
bsf STATUS, RP0 ';Bank 1 
call 0x3FF ';Get the cal value 
movwf OSCCAL ';Calibrate 
bcf STATUS, RP0 ';Bank 0 
end asm 

This will get the 12F675 up to 4MHz if the cal byte was not erased.
This code compiles okay for MikroBasic Pro so hopfully it will compile in C.

One other thing, it appears your code is in C; so maybe you should post in that forum (mikroC PRO for PIC General).
This is the basic forum and the beta at that.

I am not picking on you, just letting you know you would probably get quicker info if posting in the correct forum.

Durango

Post Reply

Return to “mikroBasic PRO for PIC Beta Testing”