CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

EX_RS485.c CCS C [Solved]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

EX_RS485.c CCS C [Solved]
PostPosted: Wed Jun 10, 2020 10:25 am     Reply with quote

Main Hardware: 2 Mikroe Easypic v7 Boards: no Glcd's/LCD's Plugged into either board

PROC: 18f46K22 both boards
Using MPLAB 8.92 with the ICD 3 on one laptop
and PCWH with ICD U80 on other laptop
Compiler version used on both 5.093

1 - Microchip ICD3 Plugged into board 1 for debugging etc
1 - CCS ICD U80 Plugged into board 2 " " "
2 - RS 485 Click boards plugged into the mikro bus socket 1 on each board (mikro-989 5V version) 1 board has the bias in place, the other not, both boards with termination jumpers left in place

2 - laptops 1 conected to each debugger for each board






















using the USB UART I/F conection on each V7 board for the RS232 to laptop

Confirmed I can comunicate with both laptops to each board through the RS 232

Here are changes made to 1st EX_RS485.c

Code:

#include "18F46K22.h"
#device ADC=10
#device *=16
#device PASS_STRINGS=IN_RAM

//My fuse settings
#FUSES NOWDT,HSH,PLLEN,NOBROWNOUT,PUT,MCLR,NOCPD
#FUSES NOSTVREN,NOPROTECT,NOPBADEN,NOWRTD,NOEBTR,NOWRT
#FUSES NOIESO,NOHFOFST,TIMER3C0,CCP3E0

#use delay(crystal=8Mhz,clock=32Mhz)

//using UART 2 for the RS232 to PC/Laptop PINS D6 TX and D7 RX

#use rs232(UART2,baud=9600,ERRORS, stream=PC) //Text through the UART


In the include RS485.c driver file used by the EX_RS485.
I have changed

Code:

#ifndef RS485_ENABLE_PIN
  #define RS485_ENABLE_PIN   PIN_C0   // Controls DE pin.  RX low, TX high.
  #endif


I have commented out the RX enable define for B5 as the Mikroe click boards have this tied low anyway so not needed.


In the Ex_RS485 C file I have changed from TRUE

Code:

#define  RS485_USE_EXT_INT    FALSE //use uart


In the EX_RS485 file i have changed the INT_RDA to INT_RDA2 for the RS232, I use the PCWH IDE Serial Monitor to see the RS232 data on each laptop, as stated I see this and can communicate from each laptop to V7 board and get a response. I don't seem to getting anything from the RS485 side though

Code:

int8 OUR_RS485_ID = 0x01;  //address for the other board is 2
#define RS485_ID OUR_RS485_ID


I have connected the RS485 click boards to each other '+' to '+' and '-' to '-' and GND to GND with 3 twisted wires together.
Obviously I can not post either the driver file or the Example due to forum rules etc, it is a long time since I have done anything like this and am a bit rusty, so I hope some of you might be able to point me in the right direction.

Thankyou
Regards
Dave

PS forgot to add I have searched the forun trying to find something that might help and still am


Last edited by diode_blade on Thu Jul 23, 2020 9:43 am; edited 3 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Jun 10, 2020 11:23 am     Reply with quote

The RS485 'turn round'. The signal that controls whether a board is
transmitting/receiving, is the R/T pin on the board you have. This
needs to be controlled by the RS485_ENABLE_PIN.
Without this either both boards will be receiving or both transmitting.
RS485, is half duplex. It must have the turnround.....
It is pin 16 on the connector. Marked as PWM.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 11, 2020 3:49 am     Reply with quote

Thanks Ttelmah,
I have assigned (well think I have) that pin already to in the RS485.c file to the correct PWM on the Mikrobus socket I am using on the V7 board.
Regards
dave

Code:

#ifndef RS485_ENABLE_PIN
  #define RS485_ENABLE_PIN   PIN_C0   // Controls DE pin.  RX low, TX high.
  #endif
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 11, 2020 5:07 am     Reply with quote

curious question....

i see you have used....
#include "18F46K22.h"

but the EasyPIC boards come with the 18F45K22( I downloaded the datasheet)

did you upgrade the PICs to 46k22 ??
If not, you may have 'problems' later on with more complicated programs that need more memory.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 11, 2020 5:56 am     Reply with quote

temtronic wrote:
curious question....

i see you have used....
#include "18F46K22.h"

but the EasyPIC boards come with the 18F45K22( I downloaded the datasheet)

did you upgrade the PICs to 46k22 ??
If not, you may have 'problems' later on with more complicated programs that need more memory.


Hi Temtronic,
Yes I am using the 46K22 in the boards. As for a few on here my goto Device.
Dave
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 11, 2020 6:09 am     Reply with quote

good to hear... it's my 'Swiss Army Knife' PIC !!! I've yet to run out of memory or pins, got real close last year though....1 spare pin !
I dedicate ICSP pins for, well, ICSP......saves a few headaches .
it would be nice to find a 'protoboard' with good layout for smaller projects, especially 'proof of concept' projects that need real world testing.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 11, 2020 6:28 am     Reply with quote

I have used the Mikroe "Ready for PIC" boards. They do a 28 pin and 40 pin for small projects I have done before. It has a small prototyping area to one side, as well as access to ISCP pins and a USB Uart.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Jun 11, 2020 7:04 am     Reply with quote

Obvious one thing not said. You need to be enabling INT_RDA2, not INT_RDA.
Another change needed in rs485.c

Now, thinking about it, if I remember correctly the K22, has the ICSP pins on
the UART2 pins. You talk about using the IDE, which suggests a possible
clash?.

Then there is another potential issue. The internal #USE RS232 lines
default to being loaded in rs485.c - Have you removed these?. If so
double check, since there are two sets of these.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 15, 2020 6:42 am     Reply with quote

Ttelmah wrote:
Obvious one thing not said. You need to be enabling INT_RDA2, not INT_RDA.
Another change needed in rs485.c

Now, thinking about it, if I remember correctly the K22, has the ICSP pins on
the UART2 pins. You talk about using the IDE, which suggests a possible
clash?.

Then there is another potential issue. The internal #USE RS232 lines
default to being loaded in rs485.c - Have you removed these?. If so
double check, since there are two sets of these.


Thanks Ttelmah, i was begining to wonder if something like that, Thanks for the heads up will try what you suggest.
Thanks Dave
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Jun 15, 2020 6:46 am     Reply with quote

I Think what I would do, is not edit rs485.c, but instead setup your
own 'version', that has your own initialisation, and then copy and paste
the functions across, checking each once for 'port specific' code as I went.
Much more likely to work... Smile
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 15, 2020 1:41 pm     Reply with quote

Mr T brings up a very important point..
always...
ALWAYS...
copy and rename drivers BEFORE you edit them !!!
NEVER,EVER modify the original CCS or other supplied drivers.
I can't stress that enough

Mind you IF you want to lose a lot of hair and several nights of sleep..just make 2 or 3 'simple' changes to a driver at the same time at the end of a marathon coding session.....

Jay
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 17, 2020 3:56 am     Reply with quote

Thanks for the tips guys, after having a few days away from it, am going to try again. Yes I do make copies of the driver/header files i use for each project, they have their own directory.
So I am going to strip right back and just try to do the basics first.
Thanks
dave
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Jun 17, 2020 4:06 am     Reply with quote

I was actually trying to suggest going 'slightly further'.
The point is that what you are doing is much more fundamental than
just a mod to the file. You need different initialisations, different interrupt
enables and usage, etc. etc..
So I'd be looking at building rs232com2.c, and actually copying the routines
from the code example, modifying each one as it is brought across. Very Happy
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 17, 2020 7:50 am     Reply with quote

Right first of all a big big thank you Ttelmah and temtronic.
I did as suggested stripped everything back, just did simple code. I have both RS485 and RS232 working. Ok even with the 485 it's just point to point, but it's a working start. Both using hardware UART/UART2 respectively on each V7 board along with their RS485 click boards. I can talk to both boards from laptops and see RS485 data I send (just a count figure).
Using serial buffered routines as in ISR_SISR example for both Int_RDA and INT_RDA2.
So thanks gents, really appreciate it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Jun 17, 2020 7:51 am     Reply with quote

Well done. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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