|
|
View previous topic :: View next topic |
Author |
Message |
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Thu Aug 11, 2011 10:09 am |
|
|
Sorry for writing to this topic, but I didn't want to open a new one for this:
using printf on rs-232, on the PC I receive only the first character of several.
For eg. with printf("adc"); I only receive 'a'
PIC type is 16f690.
I guess that in other circuit, other processor did the work.
thank you
Settings:
Code: |
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,errors)
#FUSES NOWDT //Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOCPD //No EE protection
#FUSES PUT //Power Up Timer
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled |
|
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Thu Aug 11, 2011 10:55 am |
|
|
Can you write a little sample program that displays your problem? |
|
|
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Thu Aug 11, 2011 11:32 am |
|
|
Hello!
Sure.
Code: |
#include "F:\Project\16f690 proba\690_uj.h"
#define LED_G PIN_C0
#define LED_Y PIN_C1
#define voltage 3
#define current 7
char f;
unsigned int adc_value;
#int_RDA
void RDA_isr(void)
{
}
#int_TIMER1
void TIMER1_isr(void)
{
output_toggle(LED_Y);
output_toggle(LED_G);
restart_wdt();
set_timer1(32768);
}
void main()
{
setup_adc_ports(sAN2|sAN3|sAN7|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
//setup_wdt(WDT_2304MS|WDT_TIMES_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC);
setup_timer_2(T2_DISABLED,0,1);
set_pwm1_duty(0);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_TIMER1);
setup_oscillator(OSC_8MHZ);
output_high(LED_Y);
output_low(LED_G);
enable_interrupts(GLOBAL);
do
{
disable_interrupts(GLOBAL);
set_adc_channel(voltage);
adc_value=read_adc();
//adc_value=0xf0;
putc(adc_value);
printf("\f\r\n12356");
delay_ms(1000);
enable_interrupts(GLOBAL);
}while(1);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 11, 2011 1:23 pm |
|
|
Your empty #int_rda routine is wrong. You need to get the character to
stop the RDA interrupt from continuously firing. Add the lines shown in
bold below:
Quote: |
#int_RDA
void RDA_isr(void)
{
char c;
c = getc();
}
|
|
|
|
miketwo
Joined: 04 Aug 2010 Posts: 24
|
|
Posted: Thu Aug 11, 2011 1:34 pm |
|
|
FWIW, I've experienced a similar problem to the original poster.
I have 2 PIC24F processors hooked up to each other over UART, and the communications between them is seemingly rock-solid with one exception. Of the two processors, only one is connected to a PC. The other must pass its messages through the first to have it display on the PC. If I boot them up at the EXACT same time, the bootup messages from the 2nd seem to crash the UART of the first. It hangs until the watchdog blasts it, then it's fine.
My question is similar to the OP's -- if I have ERRORS enabled in my #use rs232, what would cause this?
Some code (sorry about the layers of indirection -- I have many defines)
Code: |
//==================================================================
// Serial Port Initialization
//===================================================================
#use rs232(baud=COM_A_BAUD, UART1, bits=8, STREAM=COM_A, ERRORS)
#use rs232(baud=COM_B_BAUD, UART2, bits=8, STREAM=COM_B, ERRORS)
#use rs232(baud=COM_C_BAUD, UART3, bits=8, STREAM=COM_C, ERRORS) // To/From other PIC
#use rs232(baud=COM_D_BAUD, UART4, bits=8, STREAM=COM_D, ERRORS)
// Note that COM_C_BAUD is defined as 115200
|
As the device inits, it runs the following:
Code: |
setup_uart(COM_A_BAUD, COM_A); //
setup_uart(COM_B_BAUD, COM_B); //
setup_uart(COM_C_BAUD, COM_C); //
setup_uart(COM_D_BAUD, COM_D); //
|
Finally, if the freeze happens, it's in this section of code:
Code: |
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_64,0x00FA); // 0x00FA is a period of 250, which at 32MHz and a prescaler of 64, should rollover every millisecond
enable_interrupts(INT_RDA); // This is the interrupt service routine to grab incoming serial messages
enable_interrupts(INT_RDA2);
enable_interrupts(INT_RDA3); // <-- crash seems to occur here.
enable_interrupts(INT_RDA4);
enable_interrupts(INT_TIMER1);
\ |
And the interrupt is defined as the following:
Code: |
#int_rda3 // Port 2
void serial_isr3()
{
static int a;
const unsigned char SPACE= 30;
buffer2[next_in2]=fgetc(COM_C);
next_in2++;
if(next_in2>BUFFER_SIZE_C-1)next_in2=0; // rollover the circular buffer
if(PORT_HANDSHAKING[2]){
a = next_out2-next_in2;
if((a<=SPACE && a>0) ||
(BUFFER_SIZE_C-abs(a)<=SPACE && next_out2<SPACE))
{
output_high(PORT_RTS[2]); // Raise RTS to STOP
}
}// Handshaking
}
// Note that handshaking is not enabled for this port.
|
Any help or insight is appreciated. |
|
|
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Thu Aug 11, 2011 4:01 pm |
|
|
Thank You very much PCMProgammer |
|
|
Pulsartomi
Joined: 26 May 2010 Posts: 17
|
|
Posted: Fri Aug 12, 2011 4:46 am |
|
|
Finally, i've got what could cause some errors:
The max 232 circuit is faulty.
I've deleted the INT_RDA and changed the rs-232 interface too.
Now it is budging.
Thank You |
|
|
miketwo
Joined: 04 Aug 2010 Posts: 24
|
|
Posted: Tue Aug 23, 2011 11:38 am |
|
|
I managed to fix mine too. The key? Enable the interrupts BEFORE using setup_uart(), so they're ready to go as soon as the floodgates are open. |
|
|
|
|
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
|