Someone-s-out-there / ProjectCarHAN

0 stars 0 forks source link

[BUG] UART RX not working #66

Closed Someone-s-out-there closed 8 months ago

Someone-s-out-there commented 8 months ago

Describe the bug currently the uart rx is not working as intended. it doesnt seem to receive the characters

To Reproduce Steps to reproduce the behavior:

  1. Flash the code in code block 1
  2. open a serial term
  3. type some characters and press enter
  4. see no output back on the terminal

What has already been tried Note down what has already been tried

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

code block one

#define F_CPU 16000000ul

#include <avr/io.h>
#include <stdint.h>
#include<util/delay.h>
#include"libUart.h"
int main(void){
  //DDRB |= (1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(DDB2)|(DDB1);
  DDRB |= (0x3F);
  uart_init();
  PORTB = 0x01;
  RXBuff_t buffer;
  uart_set_rxBuffer(&buffer);
  while (1) 
    {
      if(buffer.linecomplete){
    uart_puts(buffer.buffer);
    buffer.buffer_IDX = 0;
    buffer.linecomplete = 0;
      }

      _delay_ms(100);

    }
}

code block 2


extern char                         uart_outbuf[UART_RX_BUFFER_SIZE + 1];
extern char                     uart_rxbuf[UART_RX_BUFFER_SIZE + 1];
extern volatile unsigned char       uart_rx_linecomplete;
extern volatile unsigned char       uart_rx_pos;    // end of string in rx

  ISR(USART_RX_vect)
  {
      unsigned char c;
      c = UDR0;             // Fetch the received byte value into the variable "ByteReceived"
      //UDR0 = c;               // Echo back the received byte back to the computer

      uart_rxbuf[uart_rx_pos] = c;
      //UDR0 = c;
      if ((c == '\n') || (uart_rx_pos > UART_RX_BUFFER_SIZE - 1)) {

          uart_rxbuf[uart_rx_pos] = 0;
          strcpy(uart_outbuf, uart_rxbuf);
          uart_rx_linecomplete = 1;
          } else {
          uart_rx_pos++;
      }
  }
Someone-s-out-there commented 8 months ago

currently testing with just echoing the character back. by reading adn writing, interrut not working needs testing with SEI() macro

Someone-s-out-there commented 8 months ago

needed marking of variables as volatile