|
|
View previous topic :: View next topic |
Author |
Message |
camleot23
Joined: 16 Aug 2019 Posts: 52
|
[SOLVED] dsPIC33EP UART2 Interrupt Problem |
Posted: Fri Nov 08, 2019 1:43 am |
|
|
Hello again,
I use CCS C compiler version 5.016 in MPLAB IDE v5.25. I have a problem
with UART2's interrupt. It is not triggering when I have data on B5 pin. I
want to read data from HZ-1050 module. It is baud rate can be configured.
I searched on the forum I saw people who had similar problems with me but
I couldn't implement them to my code and also some of them didn't work for
me. Could you help me for this problem? Here is my code:
NOTE: I have a SIM Module and it is on another rs232 -hardware uart- stream
that name is GSM. When I activate interrupt and try to get data from
__RFID STREAM CHANNEL__ the interrupt gets data from __GSM STREAM
CHANNEL__ even if I set "fgetc(RFID)" like this. It read data from GSM
stream channel and I could see them on my RS485 data. I just wanted to
mention about this problem.
Code: |
#include <./33EP64MC204.h>
#DEVICE NESTED_INTERRUPTS=TRUE
#device PASS_STRINGS=IN_RAM
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES FRC
#use delay(internal=80MHz)
#use i2c(master,I2C1,FAST)
#pin_select U1TX=PIN_B9
#pin_select U1RX=PIN_C6
#use rs232(UART1, baud=115200,parity=N,stop=1, ERRORS, stream=GSM)
#pin_select U2TX=PIN_B11 //UART RFID PINS I DON'T USE THIS TX PIN, IT IS NOT CONNECTED
//TO ANYWERE
#pin_select U2RX=PIN_B5 //I USE THIS
#use rs232(UART2, baud=9600, ERRORS, stream=RFID) //UART RFID
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_B6 ,rcv=PIN_B7,enable =PIN_B8, stream = RS485) //SOFTWARE RS485
#include <stdio.h>
#include <stdlib.h>
#include <./STRING.H>
#include <./MATH.H>
#define RFID
BOOLEAN flag = TRUE;
int j = 0;
char RFIDRecieverBuffer[200];
#ifdef RFID
#INT_RDA2 LEVEL=5
void serial_interrupt(void) {
do {
RFIDRecieverBuffer[buffer_ind] = fgetc(RFID);
buffer_ind++;
flag = TRUE;
output_low(PIN_A2);
} while (kbhit(RFID));
}
#endif
void main() {
setup_oscillator(OSC_INTERNAL, 80000000);
#ifdef RFID
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
#endif
ClearGSMRecieverBuffer();
fprintf(RS485, "starting");
output_high(PIN_A2);
for (i = 0; i < 200; i++) GSMRecieverBuffer[i] = '\0'; //CLEAR ARRAY
buffer_ind = 0;
while (1) {
//******************************************************************************
// I used this for getting data with Software UART and I could got
// RFID card ID with this two line of codes.
// RFIDRecieverBuffer[0] = fgetc(RFID);
// fprintf(RS485,"%d",String[0]);
//******************************************************************************
//***************HARDWARE PRINTING CODES***************************************
if(flag){
for (j = 0; j < 200; j++) {
if (RFIDRecieverBuffer[j] == '\0') continue;
fprintf(RS485, "%c", GSMRecieverBuffer[j]);
}
flag=FALSE;
for (i = 0; i < 200; i++) GSMRecieverBuffer[i] = '\0';//CLEAR ARRAY
buffer_ind = 0;
}
}
} |
Last edited by camleot23 on Fri Nov 08, 2019 5:44 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Nov 08, 2019 2:20 am |
|
|
Possibly the output is not actually going high enough.
Now the HZ1050, is nominally a 5v device, but they then specify
3.3v to 5.5v for the supply range.
Does your board does have a 5v supply for the device?.
If not, then I doubt it's output will be going high enough.
The unit uses an ATMega8 internally. This has a Voh of just 2.2v when
running off 3.3v. At 5v the Voh is instead 4.2v.
The input you are connecting to, has a Vih assuming you are using a 3.3v
supply of 2.64v, so the signal may not actually be getting high enough to
be seen.... |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Fri Nov 08, 2019 2:30 am |
|
|
Hi Ttelmah,
Yes I have 5v supply on my board and I can see the data that is sent from
HZ-1050 with oscilloscope and it is high enough like 5V. I don't think the
problem is about signal levels. Even if there would be a problem with logic
levels, how could I get data via software rs232? (I couldn't post this, I tried
Software rs232 and I could get data.)
What else can it be? Is there any problem with UART2 compiler bug? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Nov 08, 2019 5:04 am |
|
|
You have a major fault in your code, which will be causing issues.
Later compilers will spot it, but yours doesn't. You have defined RFID to
a different value, when it is already used as the STREAM name. This means
your putc/getc operations are not actually talking to the stream..... |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Fri Nov 08, 2019 5:29 am |
|
|
You mean #define RFID line is causing problems because I have decleared a
stream name with the same name? If it is so, I've deleted #define line and tried
it again and no, it didn't work again I suspect that I couldn't be clear about my problem.
My problem is about interrupt itself. I can't enter into interrupt function. Because I turn a LED on
on my board before "while" and after "main" and I turn it off in my interrupt function. However , while I try to send data,
my LED still stays on. So, it means interrupt is not working.
EDIT: My bad, it is working. The problem was about #define line. After I've deleted it worked. At first, I forgot activating interrupts :D .Thank you Ttelmah. What would I do if you didn't help me :D Thanks a lot. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Nov 08, 2019 7:43 am |
|
|
When you create a stream, it almost does a 'invisible define' of the value,
but you can't use it as a define. You can though 'test it. So you could
replace your 'ifdef' lines with:
#if (RFID!=0)
and this will test as 'TRUE' if the RFID stream is declared. Will though give
an undefined identifier warning when RFID is not defined.
Designed to catch you out.... |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Fri Nov 08, 2019 9:08 am |
|
|
Hmm.. I see, I didn't know this. Thank you again. You always teach me new things |
|
|
|
|
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
|