View previous topic :: View next topic |
Author |
Message |
almhuq
Joined: 14 Jan 2005 Posts: 4
|
RS232 & SIOW |
Posted: Sat Feb 23, 2008 7:33 pm |
|
|
I'm trying to run an example CCS program. The program is using the RS-232 port. While entering the values 1+2 in the Serial Monitor Input/Output Windows (SIOW) , I don't receive any data from RS232 port and onto my pc, I can only transmit data stream but can't receive over RS232 port.
Here is the example program
#include <18F4520.h>
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232 (baud=9600,xmit=PIN_C6,rcv=PIN_C7, stream=RS232)
#include <stdlib.h>
#include <input.c>
void main (){
long a,b,result;
char opr;
setup_timer_0(RTCC_INTERNAL);
while(TRUE){
delay_ms(100);
printf("\r\nEnter the first number: ");
a=get_long();
do {
printf ("\r\nEnter the operator (+-*/): ");
opr=getc();
}while(!isamoung(opr,"+-*/"));
printf("\r\nEnter the second number:");
b=get_long();
switch (opr){
case '+' :result=a+b; break;
case '-' :result=a-b; break;
case '*' :result=a*b; break;
case '/' :result=a/b; break;
}
printf("\r\nThe the result is %lu ",result);
}
} |
|
|
Guest_7068 Guest
|
|
Posted: Sat Feb 23, 2008 8:05 pm |
|
|
I did not quite understand. If you are not receiving any data from the PIC, I am guessing you are not able to see the first printf statement ?
Make sure you are using the correct terminal and the baud rates on the PC match that on the PIC.
If you are not able to send data to the PIC, then place your cursor over the 'View Ascii' window and click on it.
Then you can start sending data from the PC to the PIC by simply typing in in. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sat Feb 23, 2008 8:59 pm |
|
|
You set up a stream statement STREAM=RS232 but didn't use it in any I/O (printf getc )
Why? Look into it for it might be your issue. |
|
|
Guest
|
|
Posted: Sun Feb 24, 2008 10:30 am |
|
|
Douglas Kennedy wrote: | You set up a stream statement STREAM=RS232 but didn't use it in any I/O (printf getc )
Why? Look into it for it might be your issue. |
I have removed the STREAM=RS232 line from the code and still when running the program I don't get the "printf" line on the PC. Through SIOW I can send data, but I can't receive anything. |
|
|
Guest
|
|
Posted: Sun Feb 24, 2008 10:33 am |
|
|
Guest_7068 wrote: | I did not quite understand. If you are not receiving any data from the PIC, I am guessing you are not able to see the first printf statement ?
Make sure you are using the correct terminal and the baud rates on the PC match that on the PIC.
If you are not able to send data to the PIC, then place your cursor over the 'View Ascii' window and click on it.
Then you can start sending data from the PC to the PIC by simply typing in in. |
Yes, indeed I don't see the printf statement. I'm using the correct terminal as well as baud rates on the PC but still no luck. I'm able to send data to the pic but not receiving anything. |
|
|
almhuq
Joined: 14 Jan 2005 Posts: 4
|
|
Posted: Sun Feb 24, 2008 12:48 pm |
|
|
All the port settings are correct (Baud =9600,Parity= None, Data bits= 8, Stop Bits= 1,Flow Control =None) , but still can't see anything on the PC SIOW terminal window. Any ideas guys ? |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Feb 24, 2008 12:54 pm |
|
|
Things you will probably need.
1) A level converter Ex MAX232
2) A cable wired so that the tx of the PIC passes through the MAX232 pins and onto the rx pin of the PC. Likewise for the tx pin.
3) A common ground wire between the PC and the MAX232 and the PIC.
4) The com port in SIOW must be the comport the cable is attached to.
5) The baud rate parity etc setting in SIOW to be the same as the PIC.
The fact that it works at least in one direction gives courage to assuming that you have most of the above. The cable or connections to MAX 232 pins for the direction that is not working would be a good place to start checking at least twice. |
|
|
almhuq
Joined: 14 Jan 2005 Posts: 4
|
|
Posted: Mon Feb 25, 2008 2:34 pm |
|
|
Douglas Kennedy wrote: | Things you will probably need.
1) A level converter Ex MAX232
2) A cable wired so that the tx of the PIC passes through the MAX232 pins and onto the rx pin of the PC. Likewise for the tx pin.
3) A common ground wire between the PC and the MAX232 and the PIC.
4) The com port in SIOW must be the comport the cable is attached to.
5) The baud rate parity etc setting in SIOW to be the same as the PIC.
The fact that it works at least in one direction gives courage to assuming that you have most of the above. The cable or connections to MAX 232 pins for the direction that is not working would be a good place to start checking at least twice. |
As a matter of fact I have a RS232 chip on my development board. I'm using the PIC18F4520 development board from CCS, INC
http://www.ccsinfo.com/product_info.php?products_id=18F452kit
All your points above have been covered, but the issue of not receiving any data on the SIOW window still remains. So all I know is I can send data to the PIC but can't receive any data value from PIC. |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Tue Feb 26, 2008 1:53 pm |
|
|
Try with something really simple first:
Code: |
#include <18F4520.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#include <stdlib.h>
#include <input.c>
#include <stdio.h>
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
setup_PIC()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
}
void main()
{
setup_PIC();
while(TRUE)
{
delay_ms(1000);
printf("\r\nThis is a test");
}
} |
Only other thing I can think of is what freq is the board running at? You set it at 20Mhz, I trust that is correct? _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
Guest
|
|
Posted: Tue Feb 26, 2008 3:04 pm |
|
|
ECACE wrote: | Try with something really simple first:
Code: |
#include <18F4520.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#include <stdlib.h>
#include <input.c>
#include <stdio.h>
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
setup_PIC()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
}
void main()
{
setup_PIC();
while(TRUE)
{
delay_ms(1000);
printf("\r\nThis is a test");
}
} |
Only other thing I can think of is what freq is the board running at? You set it at 20Mhz, I trust that is correct? |
I have tried your program and the problem still remains. I used a scope to probe the MAX232. The MAX232 can receive data but the cannot transmit data. It may be the MAX232 chip on the board is bad. I'm using CCS complier version 3.21. I don't think the complier version has anything to do with it. I just wanted to let you know. Also the frequency of the clock (20MHz) is correct on the demo board.
Do you have any other suggestions I should try? |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Tue Feb 26, 2008 3:47 pm |
|
|
In the sample I gave you, you should just be seeing data coming out of pin C7 every second. If you see the data there and on the input pin of the RS232 chip, but don't see if going out, then you may be correct...bad RS232 chip.
Only other thought:
Could it be a null vs non-null modem cable?
Could it just be a bad cable?
I recently had one go bad where either the TX or RX line was intermittently shorting to groud. That was a hair puller!
Do you have two serial ports on your computer?
Any chance there is something wrong with that port?
Or is there any device you have that you can put in place of the demo board that can send data you can recieve? If so you could single out the board from the rest of the setup. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
|