mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 click

mikroC, mikroBasic and mikroPascal for PRO ARM® MCUs, supporting STM32, Tiva, Kinetis, & CEC devices
Post Reply
Author
Message
yoonjk1991
Posts: 9
Joined: 13 Jan 2020 01:53

mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 click

#1 Post by yoonjk1991 » 17 Jan 2020 12:05

Hello
A few days ago I got a good answer. Thank you.

This time I am trying to transfer data using RS485 4 click.
"RS485_4_click" was installed on "mikromedia_Plus_for_STM32_ARM_Shield"-BUS4

Code: Select all

sbit  RS485_rxtx_pin           at GPIOE_ODR.B5;

void main() {

  Start_TP();

  UART2_Init(19200);                           // initialize UART1 module
  Delay_ms(100);
  RS485Master_Init();                         // intialize MCU as a Master for RS-485 communication

  USART2_CR1bits.RXNEIE = 1;       // enable uart rx interrupt

  GPIO_Digital_Input(&GPIOE_IDR, _GPIO_PINMASK_3);
  NVIC_IntEnable(IVT_INT_USART2);  // enable interrupt vector

  while (1) {
    Check_TP();
    if((Button(&GPIOE_IDR, 3, 1, 0)) && (a == 0)){

      RS485Master_Send(dat,1,160);
      a = 1;
    }

    if((Button(&GPIOE_IDR, 3, 1, 1)) && (a == 1)){
       a = 0;
    }
  }
}

PE5Pin responds at the press of a button,

But communication is unresponsive.
Cap 2020-01-17 18-27-15-259.png
Cap 2020-01-17 18-27-15-259.png (67.83 KiB) Viewed 4024 times
PA3-USART2 RX
PD5-USART2 TX
Can't set

What should I do?

Thank you in advance !!

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#2 Post by AntiMember » 17 Jan 2020 23:05

Maybe
GPIO_Alternate_Function_Enable(&_GPIO_MODULE_USART2_PA23);

yoonjk1991
Posts: 9
Joined: 13 Jan 2020 01:53

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#3 Post by yoonjk1991 » 20 Jan 2020 14:41

Thank you!

I solved it with "GPIO_Alternate_Function_Enable(&_GPIO_MODULE_USART2_PD5_PA3);"

----------------------------------------------------------------------------------------



I've written and read using RS485Master_Send and RS485Master_Receive.

But because of the protocol I couldn't communicate.

For example, sending (0x)"AB CD EF 12 34" sends "96 00 83 AB CD EF 12 34 29 A9",

Incoming data was blocked by the protocol.

I want to create a protocol.


Contact 1. I want to send it as is without start bit or CRC. ex) "AB CD EF 12 34"-> "AB CD EF 01 02")

Contact 2. How do I use UART interrupts?

Contact 3. Is there a way to see the source of the RS485Master_Send and RS485Master_Receive functions?
-> Is there a way to see the function source as well as this?


Thank you for your reply.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#4 Post by AntiMember » 20 Jan 2020 18:48

If you want to create your own protocol - why do you need the RS-485 Library ...
Write your receive and transmit handlers.
It:
sbit RS485_rxtx_pin at GPIOE_ODR.B5; //Set B5 - transmit, reset B5 - receive
USART2_CR1bits.RXNEIE = 1; // enable uart rx interrupt
NVIC_IntEnable (IVT_INT_USART2); // enable interrupt vector
can be used.
Interrupt handler? ..
procedure interrupt (); iv IVT_INT_USART2;
begin
Your_Master_Receive (buf);
end;
The source code of the library is a question for mikroe...

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#5 Post by filip.grujcic » 21 Jan 2020 14:27

Hello,

The source code of the compiler's libraries is not distributable due to company's policy I'm afraid.
Refer to the reference manual for your MCU in order to find more info about UART module.

Regards,
Filip Grujcic

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#6 Post by Toley » 21 Jan 2020 16:16

Thank you for answer.

mikromedia Plus for STM32 ARM(STM32F407ZG) - mikroC PRO is in use.

I'm trying to ask a question about sending, receiving UART.

There seems to be no UART TX, TR interrupt example. Is there an example?
There are no examples in the library.

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#7 Post by filip.grujcic » 22 Jan 2020 10:38

Hello,

There aren't any official examples for UART interrupt.
However, in the above post made by AntiMember you have everything you need in order to make an UART interrupt.

Regards,
Filip Grujcic

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#8 Post by Toley » 22 Jan 2020 12:47

Toley wrote:Thank you for answer.

mikromedia Plus for STM32 ARM(STM32F407ZG) - mikroC PRO is in use.

I'm trying to ask a question about sending, receiving UART.

There seems to be no UART TX, TR interrupt example. Is there an example?
There are no examples in the library.
I someone using my Nickname? I did not write that question!!!
Serge T.
Learning is an endeless process but it must start somewhere!

yoonjk1991
Posts: 9
Joined: 13 Jan 2020 01:53

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#9 Post by yoonjk1991 » 22 Jan 2020 14:51

Toley wrote:
Toley wrote:Thank you for answer.

mikromedia Plus for STM32 ARM(STM32F407ZG) - mikroC PRO is in use.

I'm trying to ask a question about sending, receiving UART.

There seems to be no UART TX, TR interrupt example. Is there an example?
There are no examples in the library.
I someone using my Nickname? I did not write that question!!!
??????

I don't know how your name is logged into my computer,

I'm sorry.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: mikromedia Plus for STM32 ARM(STM32F407ZG) - RS485 4 cli

#10 Post by AntiMember » 24 Jan 2020 13:16

//UARTIRQ
//UART interrupt usage example. Uses UART Lib.
unsigned short txc = 0;
unsigned short rxc = 0;
unsigned rxflg = 0;
unsigned rxbuf[16];
unsigned txbuf[16];

// Interrupt routine
void interrupt() iv IVT_INT_USART1 ics ICS_AUTO
{
if (USART1_SRbits.RXNE) // if uart rx DR not empty
{
rxbuf[rxc] = USART1_DR & 0x1FF; // read 9 bits from the data register
rxc++;
rxc = rxc & 0x0F; // make a circular buffer
rxflg = 1; // if symbol received - set flag
}
if (USART1_SRbits.TC) // if uart tx tracmit complete
{
USART1_DR = txbuf[txc] & 0x1FF; // write 9 bits to the data register
txc++;
txc = txc & 0x0F; // make a circular buffer
}
}

void sendsymb(unsigned symb)
{
USART1_DR = symb & 0x1FF;
}

void main()
{
unsigned i;
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);

USART1_CR1bits.RXNEIE = 1; // enable uart rx DR not empty interrupt
USART1_CR1bits.TCIE = 1; // enable uart tx tracmit complete interrupt
USART1_SRbits.RXNE = 0; // clear uart tx DR empty pending bit
USART1_SRbits.TC = 0; // clear uart tx tracmit complete pending bit
NVIC_IntEnable(IVT_INT_USART1); // enable interrupt vector

txc = sizeof(txbuf)/2;
for (i=0;i<txc;i++)
{
txbuf = '*'; // fill the transfer buffer with *
}
sendsymb(txbuf[0]); // initialize the TC interrupt by passing the first character

while (1)
{
if (rxflg) // if there is a received symbol
{
txbuf[txc] = rxbuf[rxc-1]; // the received character is transferred to the current location of the transmission buffer
rxflg = 0; // the received symbol is processed - clear the flag
}
}
}

Post Reply

Return to “ARM PRO Compilers”