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

16F1578 rs485.c problem [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
shinkokarbon



Joined: 26 Apr 2020
Posts: 2

View user's profile Send private message

16F1578 rs485.c problem [Solved]
PostPosted: Fri Jul 10, 2020 6:42 am     Reply with quote

Hi,
I tried to do communication between PIC and nRF52810 mcu with MAX485 IC . I am using rs485.c file. When i was working with pic16f1788 the communication was OK. I changed the mcu and my communication has broken. I can send data from nrf to pic but pic can't send data to nrf.

1)if i use putc function "putc(0xAA)" in main loop, i can see 8 bit output. But rs485_send_message function is not working correctly.

2) When i was working on pic16f1788, I didn't use pin_select feature. If i make comment UART pin_select, the Expect comma error occurs in rs485.c file.

3) I check the tx pin and RS485_ENABLE_PIN with ossiloscope. Enable pin is going high during the transmit operation. Tx pin is going low at beginning of the operation and going high when operation end(enable pin is going low that moment). Tx pin stay low during all the operation time, there is no data.

rs485.c
Code:

/////////////////////////////////////////////////////////////////////////
////                            RS485.c                              ////
////                                                                 ////
////      This file contains drivers for RS-485 communication        ////
/////////////////////////////////////////////////////////////////////////

#ifndef RS485_DRIVER
#define RS485_DRIVER

#ifndef RS485_ID
#define RS485_ID  0x10                 // The device's RS485 address or ID
#endif

#ifndef RS485_USE_EXT_INT
#define RS485_USE_EXT_INT FALSE        // Select between external interrupt
#endif                                 // or asynchronous serial interrupt


#if(RS485_USE_EXT_INT == FALSE)
   #ifndef RS485_RX_PIN
   #define RS485_RX_PIN       PIN_B5   // Data receive pin
   #endif
 
   #ifndef RS485_TX_PIN
   #define RS485_TX_PIN       PIN_B6   // Data transmit pin
   #endif

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

   #ifndef RS485_RX_ENABLE
   #define RS485_RX_ENABLE    PIN_B7   // Controls RE pin.  Should keep low.
   #endif

   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=8, long_data, errors, stream=RS485)
   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=8, parity = n, STOP=1,long_data, force_sw, multi_master, errors, stream=RS485_CD)
 
   #if getenv("AUART")
      #define RCV_OFF() {setup_uart(FALSE);}
   #else
      #define RCV_OFF() {setup_uart(FALSE);}
   #endif
#else
   #ifndef RS485_RX_PIN
   #define RS485_RX_PIN       PIN_B0   // Data receive pin
   #endif

   #ifndef RS485_TX_PIN
   #define RS485_TX_PIN       PIN_B3   // Data transmit pin
   #endif

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

   #ifndef RS485_RX_ENABLE
   #define RS485_RX_ENABLE    PIN_B5   // Controls RE pin.  Should keep low.
   #endif

   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, errors, stream=RS485)
   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, multi_master, errors, stream=RS485_CD)

   #define RCV_OFF() {disable_interrupts(INT_EXT);}
#endif



+++++++++++++++++++++++++++
Most of rs485.c driver code deleted.
Reason: CCS forum rule #10
10. Don't post the CCS example code or drivers, or ask for such code and drivers.
Forum rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
+++++++++++++++++++++++++++
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Fri Jul 10, 2020 7:48 am     Reply with quote

You haven't posted the code. No details of what chip etc.... Sad
shinkokarbon



Joined: 26 Apr 2020
Posts: 2

View user's profile Send private message

PostPosted: Fri Jul 10, 2020 8:19 am     Reply with quote

Ttelmah wrote:
You haven't posted the code. No details of what chip etc.... Sad

Sorry for that. I am new in forum. By the way i fix the problem. I add pin_select("NULL", PIN_B6); to my main function(B6 is Tx Pin). Problem solved.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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