Author Topic: Changing MOSI/MISO pins?  (Read 2260 times)

MrGlasspoole

  • Newbie
  • *
  • Posts: 35
  • Country: de
Changing MOSI/MISO pins?
« on: January 20, 2017, 03:23:57 PM »
Is there a way to set the MOSI/MISO pins?
I know i can do it for IRQ, SCK and CS:
Code: [Select]
RFM69 radio(rfmCsPin, rfmIrqPin, isRFM69HW, rfmIrqNum);

Is there a documentation of all the settings because the code above is from the forum?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6403
  • Country: us
    • LowPowerLab
Re: Changing MOSI/MISO pins?
« Reply #1 on: January 20, 2017, 04:11:53 PM »
No, these are dedicated pins for SPI.
The library uses the hardware SPI, does not bitbang SPI.
Are you trying to use the library on a new MCU?

MrGlasspoole

  • Newbie
  • *
  • Posts: 35
  • Country: de
Re: Changing MOSI/MISO pins?
« Reply #2 on: January 20, 2017, 04:53:13 PM »
Teensy 3.5 that has 3x hardware SPI.

I can connect the WizNET only to the first SPI because the ethernet library uses FIFO which only exists on the first SPI.

I was happy that there is now the Teensy 3.5 and 3.6 with so much SPI and thought now there are no more problems
using RFM69 and ethernet at the same time :(

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6403
  • Country: us
    • LowPowerLab
Re: Changing MOSI/MISO pins?
« Reply #3 on: January 20, 2017, 04:59:26 PM »
Oh I see. Unfortunately I don't keep up with Teensy or support anything other than the 328p and 1284p at this point for the RFM69lib, so you'll have to ask the Teensy folks how to do that.
Since the RFM69 relies on some directives to do some SPI stuff the changes might be more than just simple conditional directives for Teensy.

MrGlasspoole

  • Newbie
  • *
  • Posts: 35
  • Country: de
Re: Changing MOSI/MISO pins?
« Reply #4 on: January 20, 2017, 06:05:40 PM »
I'm not really a coder but this are two answers from Teensy users:

Quote
While working on the T3.6 beta I made a version of the Radiohead library that allows me to support SPI1.
I added SPI transaction support to the library.
I then made a copy of the HardwareSPI code to make it possible to use SPI1.
Code: [Select]
#include <SPI.h>
#include <RH_RF95.h>
#define TRY_SPI1
#ifdef TRY_SPI1
#include <RHHardwareSPI1.h>
// MISO 1, MOSI 0, SCK 20
#define RFM95_CS 31
#define RFM95_RST 37
#define RFM95_INT 2

// SPI1 Miso=D5, Mosi=21, sck=20, CS=31
RH_RF95 rf95(RFM95_CS, RFM95_INT, hardware_spi1);

// Singleton instance of the radio driver
#else
//  RH_RF95(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, RHGenericSPI& spi = hardware_spi);
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
Quote
I recently changed the Arducam library to use SPI2 rather than SPI0 on the T3.6, and all it took was a simple SPIx callout change to the Arducam library similar to what Kurt mentions. However, the RFM69 radio also uses interrupts to the host processor, so that also needs to be looked at. Possible modification of the ISR of the Moteino AVR code, etc. ???


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6403
  • Country: us
    • LowPowerLab
Re: Changing MOSI/MISO pins?
« Reply #5 on: January 20, 2017, 06:29:46 PM »
For the 2 AVRs I support there is a single SPI and it's baked into the library code.
You might have better luck with RadioHead which aims to be more generic.

MrGlasspoole

  • Newbie
  • *
  • Posts: 35
  • Country: de
Re: Changing MOSI/MISO pins?
« Reply #6 on: January 20, 2017, 08:32:04 PM »
Quick test just switching an relay on over RFM69 does work.
All i did was changing SPI to SPI1 in RFM69.cpp and RFM69_ATC.cpp.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6403
  • Country: us
    • LowPowerLab
Re: Changing MOSI/MISO pins?
« Reply #7 on: January 23, 2017, 01:02:43 PM »
Great, if that works - more power to you.
I would just watch for these statements that save and restore SPCR and SPSR - they may not be defined for Teensy or could translate differently to SPI1/SPI2 etc:

Code: [Select]
#if defined (SPCR) && defined (SPSR)
  // save current SPI settings
  _SPCR = SPCR;
  _SPSR = SPSR;
#endif