Thread: assistance required with interupts and function calling

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    10

    assistance required with interupts and function calling

    I have so far come up with the code below but I am stuck due to my limited c experience, anyone please help me change this code below so that the COMBUF_Handler(void) interrupt reads data from user & runs an adc handler function to obtain adc values then puts these values back so that the user can read them. (It would be great if the code can run continuously so that the user can just send 0x20 every 100ms and get the updated adc value each time.

    combuf.c
    Code:
    interrupt void COMBUF_Handler(void)
    {
       Rx_Buf[0] = DIF_TO_MCU; /* Read 0x20 DIF_TO_MCU data sent by user */
      
       while (Rx_Buf[0] == 0x20){
              PADC_Handler(ADC_PchannelValue); 
              }                               
       Rx_Buf[0] = ADC_PchannelValue; /* put the adc value in the rx_buf */
     }
    adc.c
    Code:
    VS2 ADC_PchannelValue;  /* PADC Value */ 
     
    interrupt void PADC_Handler(void)
    {
       /* Accumulate the value of P channel */
       AccadcValue[0] = PADC_DATA;
       /* Read P channel ADC value and store it into global variable */
       ADC_PchannelValue = (S2)PADC_DATA;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Maybe just this
    Code:
       If (Rx_Buf[0] == 0x20){
              Rx_Buf[0]=ADC_PchannelValue; 
              }
    That is, if it's space, replace with last adc sample.

    There's no need to spam the board because your first attempt got stuck in moderation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    10
    Quote Originally Posted by Salem View Post
    Maybe just this
    Code:
       If (Rx_Buf[0] == 0x20){
              Rx_Buf[0]=ADC_PchannelValue; 
              }
    That is, if it's space, replace with last adc sample.

    There's no need to spam the board because your first attempt got stuck in moderation.
    Thank you but I do not understand what you mean by if it's space, replace with last adc sample.
    My mistake, I thought I did not send anything.

    Do I not have to call the
    interruptvoidPADC_Handler(void) interupt to get the ADC_PchannelValue?
    and would this value be updated each time?

    Last edited by tomnas; 09-13-2017 at 05:55 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yes, that is the whole point of interrupt service routines.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2017
    Posts
    10
    Code:
    If (Rx_Buf[0] == 0x20){
           Rx_Buf[0]=ADC_PchannelValue; 
           }
    Sorry I am a bit confused. What you mean is if I use for example a = ADC_PchannelValue anywhere in my code it will trigger the interupt voidPADC_Handler(void)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. timing algorithm, assistance required,
    By Steven Boyle in forum C Programming
    Replies: 8
    Last Post: 02-06-2015, 08:48 AM
  2. interupts
    By C_ntua in forum C Programming
    Replies: 1
    Last Post: 10-09-2008, 06:45 PM
  3. assistance in function
    By patron in forum C Programming
    Replies: 1
    Last Post: 03-16-2008, 05:37 AM
  4. interupts?
    By crypto in forum Linux Programming
    Replies: 1
    Last Post: 11-18-2002, 06:13 PM

Tags for this Thread