Hi All,
I am using an R32C/118 micro processor (R5F64189). I am trying to use UART7 to work as the hardware layer for my modbus module.
Here is my initialisation sequence:
P15_0S = 0x03; // set p15_0 as uart TX
P15_2S = 0x00; // p15_2 is initially just a general IO
IFS0_bit.IFS05 = 0x01; // Use p15 for UART7 and set P15_2 as UART RX
PD15_bit.PD15_0 = 0x01; // Set transmit pin as output
PD15_bit.PD15_2 = 0x00; // Set receive pin as input
PD12_bit.P12_6 = 0x01; // This is my direction switch pin for 2- wire RS485, set as output here
U7MR = 0x15;
U7C0 = 0x18;
U7C1 = 0x02;
U78CON = 0x01;
S7RIC = 0x01;
S7TIC = 0X01;
U7BRG = 12; // Baudrate of 115200 for 24 kHz
U7MR_bit.PRYE = 0x00;
U7C1_bit.TE = 0x00; // these two bits are flipped in my transmit and receive functions.
U7C1_bit.RE = 0x01;
My problem is that my receiving device receives the modbus commands okay and it replies with a valid modbus command which is reaching the UART RX pin of the processor (I can see bot the RX and TX messages in my scope). But my break point in the receive interrupt is not being hit. My receive interrupt vector is UART7_RX.
When I checked the S7RIC_bit.IR bit after setting the ports to receive mode (after sending a modbus command through my transmit function), I noticed that this bit is not changing its state to 1, which is why it is not entering my RX interupt service routine? But what am I missing? I cant see anything obviously wrong in the code.
Please help!
Kind regards,
Pillasaar
Your SFR macros look funny. I don't know if you created your own MACRO set.
I clipped this from the following from our SFR definition file sfr111.h
/*------------------------------------------------------
UART7 Transmit/Receive Mode Register
------------------------------------------------------*/
union byte_def u7mr_addr;
#define u7mr u7mr_addr.byte
#define smd0_u7mr u7mr_addr.bit.b0
#define smd1_u7mr u7mr_addr.bit.b1
#define smd2_u7mr u7mr_addr.bit.b2
#define ckdir_u7mr u7mr_addr.bit.b3
#define stps_u7mr u7mr_addr.bit.b4
#define pry_u7mr u7mr_addr.bit.b5
#define prye_u7mr u7mr_addr.bit.b6
Here's the app note you need. Pay special attention to the flow charts and what they do.
http://documentation.renesas.com/eng/products/mpumcu/apn/m16c/rej05b1234_m16cap.pdf
and source code
http://am.renesas.com/support/downloads/download_results/C1000000-C9999999/mpumcu/m16c/an_rej05b1234_m16c_serial.jsp
Thanks for your reply ckgrier!
The macros that I use are from the processor library header file which was provided by IAR.
I already have the application notes you mentioned and I can't find anything different in my code.
Also, in my last post I said the RX interrupt flag is not being set, but this might not be right, the watch window is not getting updated in the IAR work bench I guess.
I tired another UART (UART6) with the same result.
I have been with this code for nearly two days now! Desperate for help!
With a UART it is OK to leave Transmit and Receive Enabled all the time. Unless you have a noisy connection. Even Half duplex should be OK since you'll get back the characters you send.
Try this in both initializations:
U7C1_bit.TE = 0x01; U7C1_bit.RE = 0x01;
U7C1_bit.TE = 0x01;
Thanks for your reply Ckgrier! I just tried that now and it still didn't work. I am kind of losing hope now.
Got it working finally!!
The problem was that I am using the 144 pin package and for enabling ports 11 to 15, you have to set the PCE bit in PCR (port control register).
And this is mentioned only in one page in the whole of the manual. I would expect a foot note in the uart section saying I can use uart in port 15 only if I have set this bit.
I wonder why the TX was working though!