• AVR Freaks

Hot!SPI Slave mode interrupt or not (poll)...

Page: < 12345 > Showing page 4 of 5
Author
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 08:21:57 (permalink)
0
Then, upon every reception of a temperature set value, write the next temperature value to the TX register. (Best in the RX ISR, as the master is not expected to transmit again any time soon.)

 
Did you see my new IRQ_SPI1RX ISR?
 
It does exactly what you suggested but I'm still getting latest received byte from the slave.

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#61
NorthGuy
Super Member
  • Total Posts : 6171
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 09:21:24 (permalink)
0
JustRob
If I were you, I would simply connect the LCD controller to the temperature sensor directly.

I can not do that as the lcd controller circuit board has to be at the end of my armrest of my wheelchair and the thermal controller circuit board has to be with the main power supply on the back of my wheelchair.



Certainly you can. You just put the temperature sensor where you need to measure temperature and you run wires to the LCD controller. The length of the wires may be several feet without causing any problems.
#62
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 09:35:52 (permalink)
0
Certainly you can. You just put the temperature sensor where you need to measure temperature and you run wires to the LCD controller. The length of the wires may be several feet without causing any problems.

 
I'm already using a 10-wire ethernet cable now.  I do not have room for the extra cabling.  There should be no need for this.  SPI communication is somewhat working and running extra wires for the thermistors is a band-aid in my humble opinion but thank you for your suggestion.  And I would still have to communicated the desired temp to my thermal controller.

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#63
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 09:52:55 (permalink)
0
Again, my spi slave interrupt isr so you won't have to go back:

// interrupt service routine
void __interrupt(irq(IRQ_SPI1RX),high_priority) spi_ISR(void){

    //slave incoming data received
    PIE2bits.SPI1RXIE = 0; // disable spi receive interrupt
    spi_incomming = 1;
    SPI1IF = 0;
    SPI1TXB = backrest_temp;
    PIR2bits.SPI1RXIF = 0;
                
}

 

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#64
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 10:01:24 (permalink)
0
And my spi-slave while loop where I receive the spi master data
while(1){

        // get current backrest temp
        adc_reading = read_adc_chan(THERMISTOR2_CHAN);
        backrest_temp = temp_lookup(adc_reading);
        
        adc_reading = read_adc_chan(THERMISTOR1_CHAN);
        heatsink_temp = temp_lookup(adc_reading);
  
        // handle new desired_temp interrupt
        if (spi_incomming){
            data_ready = SPI_data_ready();
            if (data_ready){
                SPI1TXB = backrest_temp; // load backrest_temp into transmit buffer
                desired_temp = SPI_get_return_temp();
                SPI1TXB =backrest_temp;
                spi_incomming = 0;
                
            } // data_ready
            
            PIE2bits.SPI1RXIE = 1;
        } // spi_incomming

    

 
And the SPI_get_return_temp() function:

uint8_t SPI_get_return_temp(){
    
    
    while(SPI1CON2bits.BUSY);

    
    return SPI1RXB;
    
    
}

 

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#65
NorthGuy
Super Member
  • Total Posts : 6171
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 10:02:54 (permalink)
0
JustRob
I'm already using a 10-wire ethernet cable now.  I do not have room for the extra cabling.  There should be no need for this.  SPI communication is somewhat working and running extra wires for the thermistors is a band-aid in my humble opinion but thank you for your suggestion.  And I would still have to communicated the desired temp to my thermal controller.



Certainly, if it's already working there's no reason to change it.
 
For future designs. Instead of terminators, it's possible to use integrated sensors. For example, Maxim sells 1-wire temperature sensors DS18B20. They're addressable and you can put several sensors on the same wire.
#66
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 10:27:50 (permalink)
0
temperature sensors DS18B20

Thank you.  It's actually 3 wire in that it needs power and ground adding an additional wire over thermistors.

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#67
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 10:50:43 (permalink)
0
@ NorthGuy
Running the temperature sensor to the LCD controller does make little sense: the temperature controller itself requires the current temperature as well.
 
@ Rob
Forget about keeping "ISRs as short as possible" and do the read/write within the ISR!
IIRC, on this derivative it is not possible to acknowledge the SPI IFs per writing 0 - thus your issues with getting stuck in the ISR.
The way to acknowledge/clear the RX interrupt is by emptying (reading) the RX register. (Alternative(?): setting some fancy bit that's just indicating the RX FIFO has been read. See the datasheet!)
 
AND: you do not have the initial TX register write. As your latest state was that the temperature value received (on the LCD controller) was toggling, you might be a bit slow servicing your current "spi_incoming" flag. I haven't yet checked what the temperature controller is doing "else", but might be...

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#68
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 10:56:01 (permalink)
0
Oh, now I've got what's loading your temperature controller: the single-wire protocol!
(Didn't check, but assume this must be implemented via bit-banging. Quite resource-consuming. I'd vote for a fancy analog or SPI sensor: both are not time-critical, even when implementing a second SPI port per bit-banging.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#69
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 11:04:55 (permalink)
0
Oh, now I've got what's loading your temperature controller: the single-wire protocol!
(Didn't check, but assume this must be implemented via bit-banging. Quite resource-consuming. I'd vote for a fancy analog or SPI sensor: both are not time-critical, even when implementing a second SPI port per bit-banging.

 
That post just blew me away as I have no idea what you mean by single-wire protocol, bit-banging and second SPI port...
 
I am going to try and absorb your previous post and read and write the SPI RX AND TX fifos in the SPI receive isr

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#70
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 11:21:26 (permalink)
0
@du00000001
THAT DID IT (doing everything in the isr
 
Here's my new slave while loop with isr below it:
    
    while(1){

        // get current backrest temp
        adc_reading = read_adc_chan(THERMISTOR2_CHAN);
        backrest_temp = temp_lookup(adc_reading);
        
        adc_reading = read_adc_chan(THERMISTOR1_CHAN);
        heatsink_temp = temp_lookup(adc_reading);
  
        // calculate kooling error
        if (backrest_temp >= desired_temp){
                    error = backrest_temp - desired_temp;
                    error_pos = 1;
                    error_neg = 0;
        }
        // calculate heating error
        else{
            error = desired_temp - backrest_temp;
            error_neg = 1;
            error_pos = 0;
        }

        // calculate proportional adjustment
        proportional = error * p_gain * p_gain;

        // if kooling is needed
        if(error_pos){
            kool_peltiers(proportional);
        }
            
        else if(error_neg){
            heat_peltiers(proportional);
        }
        
        else;
        
        __delay_ms(500);
        
    } // while
} // main


// interrupt service routine
void __interrupt(irq(IRQ_SPI1RX),high_priority) spi_ISR(void){

    SPI1TXB = backrest_temp;
    desired_temp = SPI1RXB;
    SPI1IF = 0;
    PIR2bits.SPI1RXIF = 0;
                
}


 
And see the signal analyzer with more importantly the history jpeg (consisent mosi and miso data):
 
THANK YOU!
 
Onward...

Attached Image(s)


Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#71
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 13:05:19 (permalink)
+1 (1)
Blown away? That easily ?  Smile
 
You wrote about using the DS-something sensor. Call it "one-wire", call it "single-wire" - that's what it's using.
Bit-banging: see  https://en.wikipedia.org/wiki/Bit_banging
Basically it's about the software to make pins toggle - as opposed to using some peripheral unit like the SPI module.
post edited by du00000001 - 2020/05/20 06:09:16

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#72
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 13:11:08 (permalink)
0
P.S.: you might even get away without touching the *IF bits: I assume these will reset automatically as a result of reading the RX register. (At least this is documented for the SPI1IF bit. Not that sure about PIR2bits.SPI1RXIF, but assuming so.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#73
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 13:13:02 (permalink)
0
Got it!!!!!

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#74
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 13:22:11 (permalink)
0
 you might even get away without touching the *IF bits: I assume these will reset automatically as a result of reading the RX register. (At least this is documented for the SPI1IF bit. Not that sure about PIR2bits.SPI1RXIF, but assuming so.)

 
If I could switch the ICD3 over easily I would verify that but alas...
 
It would be nice if Microchip came out with a dual port ICD to work with multiple boards... IMHO

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#75
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 17:35:08 (permalink)
+1 (1)
This one would be easily evaluated by attaching the debugger to the slave.
(Although "easily" might still be difficult in your specific case.)
 
Dual-target debuggers are still in their infancy, and they pose their very own challenges anyway. I prefer to have some proven design for one side, concentrating on developing/debugging a single target at a time.
But I'm as well the guy that goes with a single monitor whilst others have a small wall of monitors (2, 3, 4) these days. Different approach, successful  :)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#76
NorthGuy
Super Member
  • Total Posts : 6171
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/19 21:38:15 (permalink)
+1 (1)
JustRob
temperature sensors DS18B20

Thank you.  It's actually 3 wire in that it needs power and ground adding an additional wire over thermistors.



Even if you run full 3 wires, it's still one less than 4 wires for SPI, and eliminates the need for temperature controller as everything is handled by a single MCU.
#77
JustRob
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/20 04:42:08 (permalink)
0
 it's still one less than 4 wires for SPI

You just don't understand.  I still need to communicate back to the thermal controller board the desired temp.
 
It is all working now so the point is moot.

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#78
du00000001
Just Some Member
  • Total Posts : 3778
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/20 05:27:10 (permalink)
0
@ Rob
IMHO, everything is fine with your architecture  Smile
 
@ NorthGuy
I don't think you got the whole picture:
  • The "temperature controller" isn't just some "temperature sensor pickup" but a real "controller" - controlling some Peltier modules.
  • If you're not that familiar with Peltiers: the most-spread ones come in a "12 V flavor" - consuming single- to 2-digit Amps. Not exactly what you'd want to route to the armrest and back. In contrary, you may want to keep the power tracks as short as possible.
  • Assuming the heater/cooler is powered from the wheel chair's battery, it would be appropriate to mount the temperature controller somewhere between the battery and the locations to be heated/cooled.
    While the touch HMI has to reside where it can be touched (armrest).
Overall: that's an architecture I'd propose myself for such an application, as microcontrollers have become really cheap over the decades. And while the communications issues were a bit of annoying, there's nothing basically wrong with the architecture and the communications scheme.
post edited by du00000001 - 2020/05/20 06:10:23

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#79
NorthGuy
Super Member
  • Total Posts : 6171
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: SPI Slave mode interrupt or not (poll)... 2020/05/20 05:34:07 (permalink)
0
du00000001The "temperature controller" isn't just some "temperature sensor pickup" but a real "controller" - controlling some Peltier modules.



Sorry. My mistake. I didn't know that.
#80
Page: < 12345 > Showing page 4 of 5
Jump to:
© 2020 APG vNext Commercial Version 4.5