View previous topic :: View next topic |
Author |
Message |
TimothyCarter
Joined: 08 Aug 2016 Posts: 22
|
PIC24FJ with MODBUS on UART5 |
Posted: Mon Aug 08, 2016 10:42 am |
|
|
Has anyone attempted to get the CCS Modbus code to work using UART 5? (Forgive me if this is already in the forum, I did use search and didn't seem to find anything relating to UART 5.)
I am using the PIC24FJ256GB406, and noticed that UART 5 RX/TX was already brought out to 2 pins (PIN_D6 & PIN_D1 respectively). This is why I used (or want to use) UART 5.
(For Debugging, I am using the PICkit3 and MPLAB X - since the CCS ICD-U64 doesn't work in Debug mode for this chip.)
I noticed the Modbus driver only goes up to UART4, so in trying to modify it to make it work with UART 5, I've noticed that the PIC doesn't seem to jump to the Rx interrupt (using #INT_RDA5), setting WATCH variables, I found that the enable_interrupts(INT_RDA5) function was not actually enabling the interrupt - so I manually set the register.
I run the code, with a breakpoint in the RDA5 interrupt, send data to the PIC - but it doesn't halt. I manually halt and check the interrupt flag and notice that it is set.
So, has anyone gotten this to work? Can anyone shed some light on what I should be doing?
Thanks! _________________ “Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
- Eric S. Raymond |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Tue Aug 09, 2016 12:46 am |
|
|
First thing is to point the RDA5 problem out to CCS. They should generate a fix in a few hours only.
It's caused by the data sheet. If you look at the diagram, In Fig 8-1, it only shows interrupt vectors going up to 117. However if you look at Table 8-2, RDA5 is vector number 119. CCS didn't spot the contradiction, and have only implemented the table up it vector 117.....
Without this the interrupt will vector to reset, so your breakpoint will never be reached....
A potential 'code round', is something like:
Code: |
//suitable header for your clock etc...
#use RS232(UART5, bits=8, baud=19200, ERRORS, STREAM=U5)
int8 chr=0;
#INT_RDA5
void UART5rx(void)
{
chr=fgetc(U5);
}
#word IEC6 = getenv("SFR:IEC6")
#bit RC5IE=IEC6.15
void main(void)
{
int32 * pointer;
setup_lcd(LCD_DISABLED,0); //ensiure LCD drive is off
//enable_interrupts(INT_RDA5);
//Compiler is not setting up the IVT for this interrupt
//UART5 RX is vector 119 & IEC6:15
pointer=0xF2; //memory address for IVT 119
*pointer=UART5rx; //generate the IVT entry
RC5IE=TRUE; //enable the interrupt
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
if (chr!='\0')
{
//echo received char back
fputc(chr,U5);
chr='\0';
}
}
}
|
Test it with something much simpler than Modbus (as shown), till you can get the RDA interrupt to work. Only then try to get the real code working. |
|
|
TimothyCarter
Joined: 08 Aug 2016 Posts: 22
|
Good Catch |
Posted: Tue Aug 09, 2016 7:30 am |
|
|
I figured it had to be a compiler error, but I wanted to ask here first to make sure I hadn't missed something crucial.
I saw the Fig. 8-1, but totally skipped the Table (I see how CCS could've done that). I have let the CCS guys I've been working with about some other issues, and linked to this post.
(I did manage to figure out how to check the interrupt flag, but I knew that really wasn't an acceptable answer - that's why it's called an INTERRUPT.) - I knew there had to be a way to do it manually and was trying to find that out, coming from the C18, and only using CCS for about 2 years (plus this being my first actual project with 16-bit) - I was a bit overwhelmed. |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Thu Aug 11, 2016 2:20 am |
|
|
Might be a good idea to let microchip know about the datasheet problem too. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Thu Aug 11, 2016 1:05 pm |
|
|
It's only really a matter of actually reading it.
If you give an diagram and have 0 .. 117....
Then later have a table with numbers going higher.
Then a little bit of thought an you realise that the number can go on beyond 117. Problem is that a quick 'glance' can have you thinking that the values end at this.
There are hundreds of much worse ones in the Microchip sheets with sections contradicting one another. Formulae wrong etc..
In the early days of the PIC the MicroChip sheets were very good. Now they have to be read with a lot of care. |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri Aug 12, 2016 12:43 am |
|
|
They will never improve if nobody complains.. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Fri Aug 12, 2016 1:12 am |
|
|
Problem is that they don't pay much (if any) attention now. The people actually writing the sheets no longer seem to have contact very often with the people handling their web and email..... |
|
|
TimothyCarter
Joined: 08 Aug 2016 Posts: 22
|
|
Posted: Wed Aug 24, 2016 1:03 pm |
|
|
That's one reason I liked going to their MASTERs convention - you get to actually talk to their engineers. Not that it does much good, but you see how frustrated even their own engineers get at some of the stuff that goes on at Microchip. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 24, 2016 2:40 pm |
|
|
I told Microchip Support about the problem with 18F4550 oscillator
documentation, as discussed in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=53089&start=15
I was told by the tech that he would pass on my request, but don't
expect any updates to the data sheet because the chip is "old".
I told him it's still active and many students use it on the forum.
No reply. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Wed Aug 24, 2016 3:05 pm |
|
|
Agreed.
Go back ten years or more, and they would respond, update sheets, often give you more detailed data etc.. Now they couldn't much care, even if you have spent a lot of money with them over the years.
I think the 'design' team has been separated from the 'sales', and from the 'support'.... |
|
|
|