启用ATTINY1626 UART RX中断不触发ISR,如何解决?

huangapple go评论114阅读模式
英文:

Enabling ATTINY1626 UART RX interrupt doesn't trigger ISR, how to resolve?

问题

I have a receive interrupt issue with ATTINY1626. In pooling mode I can able to receive UART data. But it is not happening by enabling UART RX interrupt. I don't know where I missed some configuration related to interrupts.

Please suggest me if anybody faced and resolved this type of issue.

Below is the code.

  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4. #include <avr/fuse.h>
  5. #define F_CPU 16000000UL / 2
  6. #define FUSE_OSCCFG_16MHZ (0x7D)
  7. // ... (The code continues)

I tried enabling the UART RXIE configurations. Enabled Global interrupts. Even the ISR also not calling upon the receive data available on receive buffers.

Hardware path seems ok as the receive functionality working with POOLing mode.

英文:

I have a receive interrupt issue with ATTINY1626. In pooling mode I can able to receive UART data. But it is not happening by enabling UART RX interrupt. I don't know where I missed some configuration related to interrupts.

Please suggest me if anybody faced and resolved this type of issue.

Below is the code.

  1. #include &lt;avr/io.h&gt;
  2. #include &lt;avr/interrupt.h&gt;
  3. #include &lt;util/delay.h&gt;
  4. #include &lt;avr/fuse.h&gt;
  5. #define F_CPU 16000000UL / 2
  6. #define FUSE_OSCCFG_16MHZ (0x7D)
  7. //#define cli() __asm__ __volatile__ (&quot;cli&quot; ::) ///&lt; Disables global interrupts
  8. //#define sei() __asm__ __volatile__ (&quot;sei&quot; ::) ///&lt; Enables global interrupts
  9. volatile unsigned char gvc_Rxbyte = 0;
  10. FUSES = {
  11. .WDTCFG = FUSE_WDTCFG_DEFAULT,
  12. .BODCFG = FUSE_BODCFG_DEFAULT,
  13. .OSCCFG = FUSE_OSCCFG_16MHZ, // Run at 16 MHz and Calibration registers of the 20 MHz oscillator are accessible
  14. .SYSCFG0 = FUSE_SYSCFG0_DEFAULT, // Reset Pin Configured as UPDI
  15. .SYSCFG1 = FUSE_SYSCFG1_DEFAULT, // start-up time between power-on and code execution
  16. .APPEND = 0x14, // FUSE_APPEND_DEFAULT - 4K APP CODE
  17. .BOOTEND = 0x04, // FUSE_BOOTEND_DEFAULT - 1K BOOT CODE
  18. };
  19. void send_string(unsigned char uartNo, char *s);
  20. void usart0_init(unsigned long int baudRate)
  21. {
  22. unsigned int baud = 0;
  23. cli();
  24. SREG &amp;=~(1 &lt;&lt; 7);
  25. // PORTMUX.EVSYSROUTEA |= (1 &lt;&lt; 1);
  26. //uint8_t sregBackup = CPU_SREG;
  27. // cli();
  28. baud = (F_CPU / baudRate) * 4; // BAUD = (64 * fCLK_PER) / (S * fBAUD)
  29. // S is the number of samples per bit
  30. // Asynchronous Normal mode: S = 16
  31. // Asynchronous Double-Speed mode: S = 8
  32. // Synchronous mode: S = 2
  33. USART0.BAUDL = (unsigned char) baud; // Set the baud rate (USARTn.BAUD).
  34. USART0.BAUDH = (unsigned char) (baud &gt;&gt; 8);
  35. USART0.CTRLC = 0x03; // Set the frame format and mode of operation (USARTn.CTRLC).
  36. //set character size to 8. parity = none. stop bits = 1. async usart.
  37. PORTB.DIR |= PIN2_bm; // Configure the TXD pin as an output.
  38. PORTB.DIR &amp;= ~PIN3_bm; // Configure the RXD pin as an input.
  39. USART0.CTRLA |=(1&lt;&lt;USART_RXCIE_bp) | (1&lt;&lt;USART_ABEIE_bp);//0x84;
  40. USART0.CTRLB |=(1&lt;&lt;USART_RXEN_bp)|(1&lt;&lt;USART_TXEN_bp) ; // Enable the transmitter and the receiver (USARTn.CTRLB).
  41. sei();
  42. }
  43. void usart0WriteByte(unsigned char dataByte)
  44. {
  45. while(!(USART0.STATUS &amp; USART_DREIF_bm)); // wait till tx register is free
  46. USART0.TXDATAL = dataByte; // load data in the tx register
  47. }
  48. unsigned char usart0ReadByte(void)
  49. {
  50. unsigned char rxByte = 0;
  51. while(!(USART0.STATUS &amp; USART_RXCIF_bm)); // wait for rx register data
  52. rxByte = USART0.RXDATAL; // read data from the rx register
  53. return rxByte;
  54. }
  55. void send_string(unsigned char uartNo, char *s)
  56. {
  57. while(*s)
  58. {
  59. usart0WriteByte(*s);
  60. s++;
  61. }
  62. }
  63. int main(void)
  64. {
  65. //unsigned char i=0;
  66. cli();
  67. _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL_CLKSEL_OSC20M_gc | (0&lt;&lt;CLKCTRL_CLKOUT_bp )); ///&lt; To out the clock on clock out pin
  68. _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); ///&lt; To set the clock pre-scaler as DIVIDED BY 2
  69. usart0_init(115200); ///&lt; Initializing UART0 as debug interface.
  70. //_PROTECTED_WRITE(CPU_SREG, (1 &lt;&lt; CPU_I_bp));
  71. //send_string(0, &quot;System Initialized\r\n&quot;);
  72. _delay_ms(1000);
  73. gvc_Rxbyte = &#39;B&#39;;
  74. while (1)
  75. {
  76. //sei();
  77. ////gvc_Rxbyte = usart0ReadByte();
  78. //usart0WriteByte(gvc_Rxbyte);
  79. //_delay_ms(1000);
  80. }
  81. }
  82. ISR (USART0_RXC_vect)
  83. {
  84. if(USART0.STATUS &amp; USART_RXCIF_bm)
  85. {
  86. gvc_Rxbyte = USART0.RXDATAL;
  87. }
  88. gvc_Rxbyte = USART0.RXDATAL; // read data from the rx register
  89. usart0WriteByte(gvc_Rxbyte);
  90. }
  91. **

I tried enabling the UART RXIE configurations. Enabled Global interrupts. Even the ISR also not calling upon the receive data available on receive buffers.

Hardware path seems ok as the receive functionality working with POOLing mode.

答案1

得分: 2

似乎您在ISR中两次读取了USART0.RXDATAL字节。如果您的gvc_Rxbyte为0,那可能是因为第二次读取USART0.RXDATAL时覆盖了它。

英文:

It seems that you read the USART0.RXDATAL byte twice in your ISR. If your gvc_Rxbyte is 0, it might be because you overwrite it by reading USART0.RXDATAL the second time.

huangapple
  • 本文由 发表于 2023年5月29日 16:42:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定