|
|
View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
Serial Communication problem |
Posted: Fri Jul 14, 2017 8:53 pm |
|
|
Hi
I suppose I am making a very basic mistake and my serial communication don't work on any of my boards connected to the PC with a USB/TTL converter.
I wrote a short test program to try to find the problem for an available board that worked fine one month ago with the same communication with 10 bytes TX and RX:
Code: | /////////////////////////////////////////////////////////////////////
//serial communication test program
//CCS PCM C Compiler, Version 5.062, xxxxx
/////////////////////////////////////////////////////////////////////
#include <16F1847.h>
#device ADC=10
#FUSES NOWDT,PUT,MCLR
#FUSES NOPROTECT,NOCPD
#FUSES BROWNOUT,BORV25
#FUSES INTRC_IO,PLL,NOCLKOUT,NOIESO,NOFCMEN
#FUSES NOWRT,STVREN,NOLVP
#use delay(internal=32M)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,errors)
/////////////////////////////////////////////////////////////////////
#define flashled PIN_A0
short timerssincF=0;
int scomtxstartcnt=0;
int flashcnt=0;
short txupdateF=0;
int scomtxwords=0;
int scomtxw2=0;
int scomtxw3=0;
int scomtxw4=0;
int scomtxwchs=0;
short rxnewmsgF=0;
short rxfail=0;
int rxwords=0;
int rxdata0=0;
int rxdata1=0;
int rxdata2=0;
int rxdata3=0;
int rxdata4=0;
int rxdata5=0;
int rxwchs=0;
/////////////////////////////////////////////////////////////////////
#INT_TIMER1
void TIMER1_isr(void)
{
set_timer1(45536);
timerssincF=1;
}
/////////////////////////////////////////////////////////////////////
void FUNCTIONS(void)
{
if(timerssincF==1)
{
flashcnt++;
scomtxstartcnt++;
timerssincF=0;
}
//-------------------------------------------------------------------
if(flashcnt>=25)
{
flashcnt=0;
output_toggle(flashled);
}
//-------------------------------------------------------------------
if(rxnewmsgF==1)
{
rxdata2=rxdata2;
rxdata3=rxdata3;
rxdata4=rxdata4;
rxnewmsgF=0;
txupdateF=1;
}
//-------------------------------------------------------------------
if((txupdateF==1)||(scomtxstartcnt==100))
{
scomtxw2=rxdata2;
scomtxw3=rxdata3;
scomtxw4=rxdata4;
txupdateF=0;
scomtxstartcnt=0;
enable_interrupts(INT_TBE);
}
}
/////////////////////////////////////////////////////////////////////
#int_TBE
void TBE_isr(void)
{
switch(scomtxwords)
{
case 0:
{
putc(85);
scomtxwchs=85;
scomtxwords++;
}
break;
case 1:
{
putc(170);
scomtxwchs=255;
scomtxwords++;
}
break;
case 2:
{
putc(scomtxw2);
scomtxwchs=scomtxwchs+scomtxw2;
scomtxwords++;
}
break;
case 3:
{
putc(scomtxw3);
scomtxwchs=scomtxwchs+scomtxw3;
scomtxwords++;
}
break;
case 4:
{
putc(scomtxw4);
scomtxwchs=scomtxwchs+scomtxw4;
scomtxwords++;
}
break;
case 5:
{
putc(scomtxwchs);
scomtxwords=0;
disable_interrupts(INT_TBE);
}
break;
}
}
//-------------------------------------------------------------------
#INT_RDA
void RDA_isr(void)
{
switch(rxwords)
{
case 0:
{
rxdata0=getc();
if (rxdata0==85)
{
rxwchs=85;
rxwords=1;
}
else
{
rxwords=0;
}
}
break;
case 1:
{
rxdata1=getc();
if (rxdata1==170)
{
rxwchs=255;
rxwords++;
}
else
{
rxwords=0;
}
}
break;
case 2:
{
rxdata2=getc();
rxwchs=rxwchs+rxdata2;
rxwords++;
}
break;
case 3:
{
rxdata3=getc();
rxwchs=rxwchs+rxdata3;
rxwords++;
}
break;
case 4:
{
rxdata4=getc();
rxwchs=rxwchs+rxdata4;
rxwords++;
}
break;
case 5:
{
rxdata5=getc();
if (rxwchs==rxdata5)
{
rxnewmsgF=1;
rxfail=0;
}
else
{
rxfail=1;
}
rxwords=0;
}
break;
}
}
/////////////////////////////////////////////////////////////////////
#ZERO_RAM
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.5 ms overflow
enable_interrupts(INT_TIMER1);
disable_interrupts(INT_TBE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
delay_cycles(2);
FUNCTIONS();
}
}
|
Working with YAT terminal
I am sending hex 55,AA,00,00,00,FF (FF as checksum)
I tested the two cables I have, both are returning what I am sending from the PC if TX/RX are short circuit.
Want to mention that this serial com I am working with for many years.
The flash led works correct.
Any help will be much appreciated.
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Sat Jul 15, 2017 5:12 am |
|
|
OK I was curious as you covered all of the basics....so I downloaded the datasheet.
That PIC has TX and RX available on several pins. I've never used it BUT I'm thinking you need to set some register to TELL the PIC who is RX and who is TX.
If you cut a really small 'SW loopback' program,compile, then dump the listing it should show the register being set/cleared to put TX and RX onto the pins you want.
If it doesn't, then I suspect a compiler bug but I don't have that PIC or compiler.
Maybe this helps ...
Jay |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Jul 15, 2017 6:55 pm |
|
|
Hi Jay
Thank you for the answer
I am using the 16F1847 on small projects instead of the 18F26K22 because is 18 pin.
The serial communication worked in the past, now not working.
This is the LST of the rs232:
Quote: | .................... #use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,errors)
*
003C: BTFSS PIR1.TXIF
003D: GOTO 03C
003E: MOVLB 03
003F: MOVWF TXREG
0040: MOVLB 00
0041: RETURN
*
0079: BTFSS PIR1.RCIF
007A: GOTO 079
007B: MOVLB 03
007C: MOVF RCSTA,W
007D: MOVLB 00
007E: MOVWF rs232_errors
007F: MOVLB 03
0080: MOVF RCREG,W
0081: MOVWF @78
0082: MOVLB 00
0083: BTFSS rs232_errors.1
0084: GOTO 088
0085: MOVLB 03
0086: BCF RCSTA.CREN
0087: BSF RCSTA.CREN
0088: MOVLB 00
0089: RETURN |
Best wishes
Joe |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Jul 15, 2017 7:18 pm |
|
|
Hi Jay (and other members)
Finally I found a board that works.
The LST:
Quote: | .................... #use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,errors)
*
0050: BTFSS PIR1.TXIF
0051: GOTO 050
0052: MOVLB 03
0053: MOVWF TXREG
0054: MOVLB 00
0055: RETURN
*
00B0: BTFSS PIR1.RCIF
00B1: GOTO 0B0
00B2: MOVLB 03
00B3: MOVF RCSTA,W
00B4: MOVLB 00
00B5: MOVWF rs232_errors
00B6: MOVLB 03
00B7: MOVF RCREG,W
00B8: MOVWF @78
00B9: MOVLB 00
00BA: BTFSS rs232_errors.1
00BB: GOTO 0BF
00BC: MOVLB 03
00BD: BCF RCSTA.CREN
00BE: BSF RCSTA.CREN
00BF: MOVLB 00
00C0: RETURN
|
Except that the new software uses other ROM locations, can't find nothing wrong.
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Sun Jul 16, 2017 4:58 am |
|
|
hmm almost sounds like a PCB problem ?
You might consider staying with the 26K22, Yes a little bigger physically it does have MORE memory, peripherals,speed, etc. than the 1847 AND you've got experience with it. True it costs a little more BUT what is YOUR time worth? Even if you don't charge say $50/hr....you've probably spent 1-2 days( more??) chasing this nasty little problem. Time that you could have spent on another project or just relaxing.
My 'goto' chip is the 46K22 and now using the 26k22 for a 'smaller' project which seems to 'need' 2 more I/O pins !
Jay |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Wed Jul 19, 2017 11:38 pm |
|
|
Thanks for the answer Jay
I made already a few projects with the 16F1847 and they are working.
Will continue to find the problem
Best wishes
Joe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 19, 2017 11:47 pm |
|
|
gjs_rsdi wrote: | Will continue to find the problem |
Post your compiler version. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Jul 20, 2017 6:58 pm |
|
|
Hi PCM programmer
The compilers:
CCS PCH C Compiler, Version 5.059
CCS PCM C Compiler, Version 5.062
Best wishes
Joe |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Jul 22, 2017 1:55 am |
|
|
Hi
Everything works OK now.
I think the problem was that the computer don't like USB extension cables.
Thanks all and best wishes.
James |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|