|
|
View previous topic :: View next topic |
Author |
Message |
foxOnTheRun
Joined: 17 Apr 2010 Posts: 43
|
RS232 weird behaviour |
Posted: Thu May 20, 2010 4:54 am |
|
|
I'm using a 16F688 with it's built in uart:
Code: | #use rs232(uart1,baud=9600,stream=sdcard,PARITY=N,BITS=8,STOP=1)
|
I've wired it to a openLog module from sp***fun (not sure if i can write full name, so..) which has an uart too; both are working with logic level so 0..5V.
Also, using a max232 I've linked the pc to the serial line, so I can monitor what's going on (using putty).
At power up the program only execute 2 simple instructions:
Code: | fputc(0x0D,sdcard); |
This is an ENTER, I've seen some garbage already appearing on the line, so I force them out by forcing the other board to try to process it.
Code: | fprintf(sdcard,"Hello world\r"); |
This is where things get interesting, monitoring the line, on the terminal (I use putty) I only capture "ello world", the first char is missing..
Again, if I send:
Code: | fprintf(sdcard,"new test.txt\r"); |
Which is a valid command for the serial board, I get as reply "ew test.txt unknown command".. so actualy the system is eating the first char - gosh!
The PIC and the board are directly connected, TX and RX pins are inverserly matched - are there some extra settings or issue to take care of when setting up a serial link?
This is the full main.c as reference (yes, there is a LCD16x2 connected to the PIC).
Code: |
#include main.h"
#include LCD.C>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#define LED PIN_A0
char str[80]="";
int i=0;
int n=0;
int f=0;
int log=0;
#use delay(clock=8000000)
#int_RDA
void RDA_isr(void)
{
str[i]=getch(sdcard);
i++;
if (i>79) i=0;
}
#use delay(clock=8000000)
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ);
output_low(LED);
output_high(LED);
lcd_init();
printf(lcd_putc,"\fCard INIT 3s..");
delay_ms(3000);
output_low(LED);
printf(lcd_putc,"\fLogging..");
fputc(INVIO,sdcard);
fprintf(sdcard,"Hello world\r");
while(1);
} |
_________________ Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu May 20, 2010 7:13 am |
|
|
What is INVIO ? |
|
|
foxOnTheRun
Joined: 17 Apr 2010 Posts: 43
|
|
Posted: Fri May 21, 2010 2:55 am |
|
|
Oh, I forgot, it's a define for ENTER = 0x0d. _________________ Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia. |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Mon May 24, 2010 1:16 am |
|
|
What are your "#use rs232" and "setup_uart" (if used) definitions? |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon May 24, 2010 3:30 am |
|
|
I assume you have
PIC TX -> Module RX & PC RX
PIC RX <- Module TX (only ?)
What do you get on the PC if you disconnect the module and just have Pic to PC ? |
|
|
foxOnTheRun
Joined: 17 Apr 2010 Posts: 43
|
|
Posted: Fri May 28, 2010 5:14 am |
|
|
languer wrote: | What are your "#use rs232" and "setup_uart" (if used) definitions? |
First post, first 2 lines:
Code: | #use rs232(uart1,baud=9600,stream=sdcard,PARITY=N,BITS=8,STOP=1) |
_________________ Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia. |
|
|
foxOnTheRun
Joined: 17 Apr 2010 Posts: 43
|
|
Posted: Fri May 28, 2010 5:18 am |
|
|
I found something:
if I send: 0x0d (return) to confirm the data/commands the system was behaving wrongfully.
If I send printf("text-or-commands\n\r") the system was back in operation as it should.
So, I can consider the question closed, the "fault" looks like is on the receiver side.
The PIC connected to the PC was behaving perfectly fine. :) _________________ Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia. |
|
|
|
|
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
|