5 years, 9 months ago.

Disable interfaces

Hello.

I need to activate a serial port or SPI port, send some data and after that disabe the interface to reduce the power until I don’t need it. How can I do this?

Thank you in advance.

Regards.

1 Answer

5 years, 8 months ago.

Hi Jorge,

Mbed is currently working on an API that allowed you to enable and disable peripheral. Therefore, we currently have no direct way to disable any peripheral. You can however make a function that create the peripheral when called and destroy that peripheral when exit.

void peripheral(){
        SPI spi(D11, D12, D13); // mosi, miso, sclk
       DigitalOut cs(D0);
        // Chip must be deselected
    cs = 1;

    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,3);
    spi.frequency(1000000);
 
    // Select the device by seting chip select low
    cs = 0;
 
    // Send 0x8f, the command to read the WHOAMI register
    spi.write(0x8F);
 
    // Send a dummy byte to receive the contents of the WHOAMI register
    int whoami = spi.write(0x00);
    printf("WHOAMI register = 0x%X\n", whoami);
 
    // Deselect the device
    cs = 1;


}


void main(){
        while(1){
                peripheral();
                wait(1000);
        }
}

Please let me know if you have any questions!

- Peter, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!

Accepted Answer