|
|
View previous topic :: View next topic |
Author |
Message |
sambo
Joined: 17 Jun 2009 Posts: 4 Location: POLAND
|
[18F26J11] second uart |
Posted: Fri Sep 25, 2009 1:56 am |
|
|
Hi,
Can anyone help me with second uart?
Code: |
#use rs232(baud=19200, xmit=PIN_c6,rcv=PIN_c7,stream=rs1)
#use rs232(baud=4800, xmit=PIN_c5,rcv=PIN_c4,stream=rs2)
...
#pin_select u2rx=pin_c4
|
But interrupt of second uart dont work. |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 25, 2009 2:34 am |
|
|
With CCS, you can use any pin for a _software_ UART, and the compiler generates code for this. Such a 'UART', has no interrupt. You can also use the designated _hardware_ pins for a UART, and then the compiler generates code to handle this hardware.
On the 24J chips, UART1, is present on pins C6, and C7, so a hardware UART is 'seen', and the handler for this will be created. However UART2, is one of the 'remappable' peripherals, that can move to other pins. You need to have a #pin_select statement, telling the compiler to put UART2 onto pins C5, and C4, before the #use rs232 statement, or the hardware UART, won't be there, and a software UART will be used instead. Also, compiler version number, is critical. The functionality of this part of the compiler has been of 'varying' quality, so if your compiler is more than a few versions old, it may not work....
Best Wishes |
|
|
sambo
Joined: 17 Jun 2009 Posts: 4 Location: POLAND
|
|
Posted: Fri Sep 25, 2009 7:26 am |
|
|
Code: |
#include <18F26J11.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#use delay(clock=24000000)
#pin_select u2rx=pin_b5
#use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B5,bits=8)
int tmp;
#int_RDA
void RDA_isr(void)
{
}
#int_RDA2
void RDA2_isr(void)
{
tmp=getc();
}
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
delay_ms(1000);
printf("----------");
// TODO: USER CODE!!
while(1){
printf("rx:%c",tmp);
delay_ms(1000);
}
}
|
I write this code byt dont work. _________________ sory for my eng |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 25, 2009 8:18 am |
|
|
You need to setup _both_ UART pins.
CCS, only uses the hardware UART, if both hardware UART pins are used, in the USE RS232 statement. You don't have to then actually employ them, but both must be selected.
Also, what compiler version?.
Remember to add a getc, to the int_rda hanlder, or if a byte is present, this will never exit, and you will never get to the RDA2 handler.....
Best Wishes |
|
|
|
|
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
|