This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Beaglebone Black Uart Tx Rx interrupt

Hello,

I am using Beagle-bone Black Industrial Rev-c, and i want to enable Uart Tx Rx interrupt, i search for so many example codes but not get the exact one,TRM have registers but i don't know how to use them in C code, and as per requirements i cant use CAP for this, i have to use Uart4 RS485 modbus.

  • Hello Prial,

    Thanks for your question.

    I have assigned this query to the correct expert.

    Please expect responses in few business days.

    Regards,

    Vaibhav

  • Hi Prial,

    I gues you use Linux on Beaglebone Black? the kernel uart driver drivers/tty/serial/8250/8250_omap.c already configures uart TX/RX interrupts.

  • Hello Bin,

    Yes i am using Linux. I checked this but this will not suitable for my requirements and it is little bit complex method also.

    i just want to communicate through mod-bus rs485 through UART4, in this case i cannot use CAP because P9_27 is already connected with other device.

    Is there is another simple way so please help me.

    Regards,

    Prial

  • Hi Prial,

    Can you please explain what issue you have in your project with UART TX/RX interrupts and RS485 and P9_27? I don't have a picture in my mind for the relation of the three.

  • Hi Bin,

    I am newbie in Linux and beagle-bone also, i was transmitting and receiving data over uart but as per requirement i want to use Tx and Rx interrupt because I have to do RS485 and  Modbus in that, but the condition is that i cannot use CAP for this.

    I tried to use Uart registers(ref. TRM) but i dont know how to access them i dont have any idea

    Regards,

    Prial

  • Hi Prial,

    The kernel UART driver handles the UART interrupts and RS485 transmit and receive, your application only need to initiate sending and receiving based on your protocol or application. Linux application shouldn't care about hardware interrupts.

    I never used a Beaglebone CAP and am not familiar with it, but I still don't understand how the CAP is related to this. Why without a CAP you would need to know about UART interrupts (and you won't need to know about the TX/RX interrupt if you could use a CAP?). Please explain.

  • Hello Bin,

    I am in a project in which i have to configure LCD , modbus , RTC and all.

    I got to know i can use RS485 CAP, but the problem is i cannot use it because of the Pin of that CAP is already used by LCD cap, that why i was not wanting to use CAP.

    And second thing, i have to to uart Tx Rx interrupt in my c code as per requirement and i don't know how can i use them in my code, i know i can access their registers, but i don't know how can i actually implement it in code, i am very confused i tried a lot of ways but i failed. 

    if you have any idea then please help me 

    Regards,

    Prial

  • Hi Prial,

    Okay, I think the CAP thing is not relevant to the software question about UART, let's put it aside.

    i have to to uart Tx Rx interrupt in my c code as per requirement

    What is your C code? Is it a kernel module or user space program?

  • void configureSerial(int fd) {
    struct termios tio;
    memset(&tio, 0, sizeof(tio));

    // Set baud rate to 115200
    cfsetospeed(&tio, B9600);
    cfsetispeed(&tio, B9600);

    // 8N1 (8 data bits, no parity, 1 stop bit)
    tio.c_cflag |= CS8 | CREAD | CLOCAL;
    tio.c_iflag = IGNPAR;
    tio.c_oflag = 0;
    tio.c_lflag = 0;

    tcsetattr(fd, TCSANOW, &tio);
    }

    int main() {
    int uart1 = open("/dev/ttyS4", O_RDWR | O_NOCTTY);

    if (uart1 == -1) {
    perror("Error opening UART");
    return -1;
    }

    configureSerial(uart1);

    // Send data
    const char* dataToSend = "Hello, BeagleBone!";
    write(uart1, dataToSend, strlen(dataToSend));
    printf("Data Sent: %s\n", dataToSend);

    // Introduce a delay (you can adjust the duration as needed)
    sleep(5);

    // Receive and display data
    char buffer[256];
    int bytesRead = read(uart1, buffer, sizeof(buffer) - 1);
    if (bytesRead > 0) {
    buffer[bytesRead] = '\0'; // Null-terminate the received data
    printf("Received data: %s\n", buffer);
    } else {
    printf("No data received within the specified duration.\n");
    }

    close(uart1);
    return 0;
    }  this is my code and in this code i want to integrate interrupt

  • This is a Linux user space program, which cannot use hardware interrupts. Linux doesn't allow user space program directly access hardware.

  • Now what should I do for UART TX RX interrupt, I need interrupt code.

  • The UART interrupts are already handled by the kernel UART driver. Your user space program doesn't need care about them.

  • Alright, the main issue is that I am unable to determine the time taken for data transmission in my Modbus code because sometimes data is transmitted quickly while other times it takes longer. Is it possible that after the transmission is complete, a callback function is received or some indication or flags are provided? I've tried using flags, but I'm not achieving accuracy because I need to set the enable pin low after the transmission is complete.

  • I understand that the driver itself handles interrupts. Can we use the ISR routine in our code? If yes, then how can we configure it in our code? Because in our RS485 IC, which is half-duplex, we need to toggle the enable pin high and low, which we can potentially do in that routine.

  • I understand that the driver itself handles interrupts. Can we use the ISR routine in our code?

    No. This is not how Linux works.

    Because in our RS485 IC, which is half-duplex, we need to toggle the enable pin high and low, which we can potentially do in that routine.

    Your Linux user space program doesn't need to care about the RS485 DE pin. The kernel driver will handle it.

    Please study how to do RS485 programming in Linux user space. The following source code can be used as a reference.

    https://github.com/cbrake/linux-serial-test/blob/master/linux-serial-test.c

  • but I'm not achieving accuracy because I need to set the enable pin low after the transmission is complete.

    The kernel UART driver toggles the RS485 DE pin once the transmission is complete.

  • Thank You,

    i'll try and let you know