Skip to main content
Visitor II
November 16, 2022
Question

stm8s001j3 i/0 control problem

  • November 16, 2022
  • 1 reply
  • 991 views

I am having a communication problem with MAX485 ic. I am trying to change Ic receiving mode to transmit mode by using 'PB4' pin and i am using UART1 , SWIM pin as a Transmitter. in some controllers i am unable control pin in the middle working. I am giving both IC's supply is 5V.

    This topic has been closed for replies.

    1 reply

    Graduate II
    November 16, 2022

    The presentation here is weak.

    Show the HW side connectivity of the parts and paths involved.

    Show the SW side implementation, initialization and logic of what's being done.

    nrajAuthor
    Visitor II
    November 17, 2022

    Thanks for the reply, please find the below connections between controller and 485 ic0693W00000WIcRJQA1.png 

    please find below configurations and operations

    #define Tx_Enable      GPIO_WriteHigh(GPIOB, GPIO_PIN_4)

    #define Rx_Enable      GPIO_WriteLow(GPIOB, GPIO_PIN_4)

    GPIO_Init(GPIOB, GPIO_PIN_4,

          GPIO_MODE_OUT_PP_LOW_FAST);

    int main( void )

    {

    GPIO_Init(GPIOB, GPIO_PIN_4,

          GPIO_MODE_OUT_PP_LOW_FAST);

    CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);  

      UART1_Config();

      Rx_Enable;

      enableInterrupts();

    Uart_Rx[4]=Meter_id;

       len=5;

    Send_485(len);

    while(1)

      { }

    }

    void Send_485(uint8_t Length)

     {

      Tx_Enable;

      Delay(1000);

      for(int i=0;i<Length;i++)

      {

       while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)

        {

        }

       UART1_SendData8(Uart_Rx[i]);

     }

     Delay(1000);

      

      Rx_Enable;

     }

    static void UART1_Config(void)

    {

     /* EVAL COM (UART) configuration -----------------------------------------*/

     /* USART configured as follow:

        - BaudRate = 115200 baud  

        - Word Length = 8 Bits

        - One Stop Bit

        - Odd parity

        - Receive and transmit enabled

        - UART Clock disabled

     */

      

     //UART1_DeInit();

     GPIO_DeInit(GPIOA);

    GPIO_Init(GPIOA, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);

      GPIO_Init(GPIOD, GPIO_PIN_1,

          GPIO_MODE_OUT_OD_HIZ_FAST);

     UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_NO,

              UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

     /* Enable the UART Receive interrupt: this interrupt is generated when the UART

      receive data register is not empty */

     UART1->BRR1 = 0x68;

      UART1->CR2 = 0x2C;

     /* Enable UART */

     //UART1_Cmd(ENABLE);

      

      /* Enable general interrupts */

     // enableInterrupts();

    }