8 years, 6 months ago.

Using MOSI as digitalout

I am using FRDM-KL46Z to send data to RFM22B rf module. The data to be sent is 480 bytes long, but FIFO mode of the RF module has max packet length of 255 bytes. So I am using Direct Mode where the RF22 sends clock pulses and the uC has to accept these pulses and send one data bit at every rising edge. But unfortunately I don't have any free pins except previously configured SPI pins to connect to the RFM22. So is there a way I can use the MOSI pin of the KL46Z as a digital out, while also using it as SPI port in other parts of the program? Basically, the pin must be MOSI if slave select is on and function as a regular digital ouput if slave select is off.

1 Answer

8 years, 6 months ago.

It is possible by defining it both as DigitalOut and your SPI, and using pin_function(<pin_name>, <pin_function>) in your code to toggle between the two. I think for DigitalOut the <pin_function> you need is 0, for SPI you need to look it up in the reference manual/source code.

Hi, I'm getting identifier undefined error for pin_function. Is there a library for this? I can't get any more info on this elsewhere.

posted by Mohamed Azad 31 May 2016

It is an internal mbed library function. I thought it was included automatically, but apparantly not: Include in your program #include "pinmap.h" and it should work

posted by Erik - 01 Jun 2016