I'm working on a project that requires CAN bus and SPI based display and I am currently using FlexCAN_t4 and HX8357_t3 which work perfectly together.
Recently I introduced Snooze into the project in order to put the entire setup into hibernate mode as I don't have a means of cutting power.
I chose hibernate mode as it has the lowest power consumption and it does a "hard" reset when it wakes up and reinitializes all the libraries and configuration which is what I need.
I straight away ran into an issue, where the T4 would go to sleep but would not wake up (wake up is driven via a digital pin going high).
With help from KurtE I was able to fix that by adding the following code to the end function in the SPI library:
Before:
After:
After the change to SPI.end the T4 goes to sleep and wakes up from the digital pin going high.
But nowI have a 2nd issue, and I've been able to pin point it to the SPI.transfer function.
As soon as the code hits the transfer function it gets stuck there. I've reached out to duff regarding this and he will try look into it in the next week, but he suspects that the SPI register is not resetting when the T4 wakes up and therefore might be causing the issue.
I'm no expert when it comes to debugging SPI or even knowing the in and outs of it, but I figured I'd try and get a head start on this and help with gathering info to address this issue.
So as the title states, does anyone know how to check the SPI port register and reset it on a T4?
Attached is the test sketch I am using where you can replicate the issue upon wakeup from hibernate
Recently I introduced Snooze into the project in order to put the entire setup into hibernate mode as I don't have a means of cutting power.
I chose hibernate mode as it has the lowest power consumption and it does a "hard" reset when it wakes up and reinitializes all the libraries and configuration which is what I need.
I straight away ran into an issue, where the T4 would go to sleep but would not wake up (wake up is driven via a digital pin going high).
With help from KurtE I was able to fix that by adding the following code to the end function in the SPI library:
Before:
Code:
void SPIClass::end(){}
}
After:
Code:
void SPIClass::end(){
// only do something if we have begun
if (hardware().clock_gate_register & hardware().clock_gate_mask) {
port().CR = 0; // turn off the enable
//pinMode(hardware().miso_pin[miso_pin_index], INPUT_DISABLE);
//pinMode(hardware().mosi_pin[mosi_pin_index], INPUT_DISABLE);
//pinMode(hardware().sck_pin[sck_pin_index], INPUT_DISABLE);
}
}
But nowI have a 2nd issue, and I've been able to pin point it to the SPI.transfer function.
As soon as the code hits the transfer function it gets stuck there. I've reached out to duff regarding this and he will try look into it in the next week, but he suspects that the SPI register is not resetting when the T4 wakes up and therefore might be causing the issue.
I'm no expert when it comes to debugging SPI or even knowing the in and outs of it, but I figured I'd try and get a head start on this and help with gathering info to address this issue.
So as the title states, does anyone know how to check the SPI port register and reset it on a T4?
Attached is the test sketch I am using where you can replicate the issue upon wakeup from hibernate