|
|
View previous topic :: View next topic |
Author |
Message |
Oblivion
Joined: 23 Sep 2010 Posts: 13
|
18F6722 INT_RDA2 problem |
Posted: Fri Oct 15, 2010 8:30 am |
|
|
Hello all... I am trying to use 2 UARTs on 18F6722. I can use INT_RDA and INT_RDA2 separately. But i cannot use them together. I define a modbus interrupt source and i want to change it in the runtime. Here are the codes...
Code: |
#include <18F6722.h>
#fuses HS, NOWDT, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=20M)
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
void main()
{
while(TRUE)
{
if(input(PIN_D0))
{
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA
}
if(input(PIN_D1))
{
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA2
}
if(!input(PIN_D0) && !input(PIN_D1))
{
#undef MODBUS_SERIAL_INT_SOURCE
}
while(!modbus_kbhit());
......
|
Here is my modbus UART code
Code: |
#if( MODBUS_SERIAL_INT_SOURCE == MODBUS_INT_RDA )
#use rs232(baud=MODBUS_SERIAL_BAUD, UART1, parity=N,xmit=PIN_C6,rcv=PIN_C7, stream=MODBUS_SERIAL)
#define RCV_OFF() {disable_interrupts(INT_RDA);}
#elif( MODBUS_SERIAL_INT_SOURCE == MODBUS_INT_RDA2 )
#use rs232(baud=MODBUS_SERIAL_BAUD, UART2, parity=N,xmit=PIN_G1,rcv=PIN_G2, stream=MODBUS_SERIAL_2)
#define RCV_OFF() {disable_interrupts(INT_RDA2);}
#else
#error Please define a correct interrupt source
#endif |
I cannot change the interrupt source to INT_RDA2 from INT_RDA. It is always INT_RDA and i can only use UART1. When i define it as INT_RDA2 at the beginning then it is always INT_RDA2 and only UART2. I cannot change it with "#undef and #define" in the runtime. Obviously i am forgetting something. Can you help me with this?
Thanks for your concern...
CCS version:4.110 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 15, 2010 12:03 pm |
|
|
Quote: | I cannot change the interrupt source to INT_RDA2 from INT_RDA. It is
always INT_RDA and i can only use UART1. When i define it as INT_RDA2
at the beginning then it is always INT_RDA2 and only UART2. |
This behavior would occur if you are not using streams. If you don't use
streams, the last #use rs232() statement is the one that is in effect for
all code that comes after that line.
If you are using putc(), getc(), printf(), etc., you will see this problem.
You need to use fputc(), fgetc(), fprintf(), etc., and specify the correct
stream in each line. Also, kbhit() requires a stream (if you are using
streams).
If you have constants in your fputc(), fgetc(), etc., statements, make sure
the constant is for the correct stream. Check your #ifdef, #endif, etc.,
blocks to make sure the correct #define statements are invoked. In other
words, carefully review the whole program. |
|
|
Oblivion
Joined: 23 Sep 2010 Posts: 13
|
|
Posted: Fri Oct 15, 2010 2:05 pm |
|
|
Thanks for your concern...
Quote: | If you don't use
streams, the last #use rs232() statement is the one that is in effect for
all code that comes after that line. |
Because of "#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA" the first #use rs232() statement is the effective one no matter what.
Isn't the #use rs232() statements in the "modbus UART" part of my program enough to define the streams?
And i am using putc(), getc(), printf() etc. statements for the proper streams. But it doesn't change anything.
I guess my problem occurs because of the modbus serial interrupt source definition. I cannot change it with other #define statements (the part below while(TRUE))... I am searching the forum for a week and checked the codes for million times but i still don't know how to fix this... |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Oct 18, 2010 2:15 am |
|
|
Code: |
if(input(PIN_D0))
{
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA
}
if(input(PIN_D1))
{
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA2
}
if(!input(PIN_D0) && !input(PIN_D1))
{
#undef MODBUS_SERIAL_INT_SOURCE
}
|
You are trying to use pre-compiler directives (#define and #undef) as part of your program!
I have never tried this myself but I would expect the compiler to just execute the directives in order, ignoring the C code so you get:-
Code: |
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA2
#undef MODBUS_SERIAL_INT_SOURCE
|
And then when it compiles you get:-
Code: |
if(input(PIN_D0))
{
}
if(input(PIN_D1))
{
}
if(!input(PIN_D0) && !input(PIN_D1))
{
}
|
I doubt very much it will do what you think it will. Are you expecting the correct define to be used based on the state of the pins? |
|
|
Oblivion
Joined: 23 Sep 2010 Posts: 13
|
|
Posted: Mon Oct 18, 2010 2:39 am |
|
|
Thanks for your answer Wayne_;
I was doubting that can be the mistake too. You are right. The compiler just executes the directives and ignoring the C codes at the beginning.
Code: |
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA
#undef MODBUS_SERIAL_INT_SOURCE
#define MODBUS_SERIAL_INT_SOURCE INT_RDA2
#undef MODBUS_SERIAL_INT_SOURCE |
This is exactly what i am getting...
And you are right about what i want. I want use proper defines and proper UARTs, based on the D0 and D1 pin states. I need to use "if" (or something like it) statement but the compiler doesn't allow "#if(input(PIN_D0))" expression. Can you help me with this? How can i check the pin states with a pre-compiler directive. Or is there another way? |
|
|
macias86
Joined: 22 Apr 2011 Posts: 9
|
|
Posted: Sun Apr 24, 2011 2:24 am |
|
|
Did You solve the problem? Can you use two uart interrupts together? |
|
|
|
|
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
|