Go Down

Topic: call a function from another chip? (Read 977 times) previous topic - next topic

naut

greets

I have an Attiny 2313A-PU and was wondering if there is a way for the code in it to call a function in the code located on another chip? In my case the code would be on an 328P-PU on an Arduino UNO.

Delta_G

One chip can't run code on another chip.  You'll have to establish some sort of communication between them and ask the second chip to run that code for you and report back to you on the results.

naut

do you know a tutorial that explains how to setup (serial?) communication between an Attiny2313a and an Atmega328p (as master) ? Or a library/code?

Delta_G


do you know a tutorial that explains how to setup (serial?) communication between an Attiny2313a and an Atmega328p (as master) ? Or a library/code?


http://www.lmgtfy.com/?q=arduino+serial+tutorial

Perhaps if you explain what you are trying to accomplish someone could help a little more.

majenko

You could use my ICSC (Inter-Chip Serial Communication) library that I'm working on:

https://sourceforge.net/projects/arduino-icsc/
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

naut

I want to use the 2313a for serial shiftIN, to multiplex buttons and keypads (to use less pins on the UNO), 'cause I don't have any multiplex IC's.

Quote
You could use my ICSC (Inter-Chip Serial Communication) library that I'm working on:

https://sourceforge.net/projects/arduino-icsc/


thanks, I'll look into it.

naut

I've managed to establish serial communication between two 328P-PU's, however there is one problem:

I'm building a midi controller and I want to have the main code (incl. MIDI Library) on a 328P-PU and use an attiny2313a to multiplex/shiftIn an array of buttons to the 328P-PU.

I've tried different setups yesterday to see how I would deal with the 2kb flash memory limitation of the attiny2313a. I chose Attiny2313a as the target board to see if a sketch including the MIDI library would fit on it, it doesn't. Here's the sketch:

Code: [Select]
#include <MIDI.h>

PROGMEM byte buttonNumber[8] = {1,2,3,4,5,6,7,8};
boolean currentButtonState;


void setup() {

  MIDI.begin();
  for (byte a = 0; a<1; a++) {
    pinMode(buttonNumber[a], INPUT); 
    digitalWrite(buttonNumber[a], HIGH);
  }

}

void loop() {
 
  for (byte i = 0; i<1; i++) {
      currentButtonState = digitalRead(buttonNumber[i]);
       
        if (currentButtonState == LOW) {
          MIDI.sendProgramChange(buttonNumber[i], 10);
          delay(250);
        }
    }
}


Then I tried the sketch without the MIDI library, instead I used the Serial library to send messages to the 328P on the UNO, that did not work, or at least I don't know how to set up communication if the two chips have the serial ports running at different baud rates, i.e. MIDI library at 31250 and the Serial library at 9600.

I don't know what to do now, can you guys give me a hint?

majenko

MIDI is just Serial running at 31250 baud.  You can create MIDI streams manually without using the MIDI library.  Learning the MIDI protocol might help: https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html

Then you can just use the attiny as a MIDI instrument manually sending the note on / note off commands over serial.

The 328P will have to run at 31250 baud and be a MIDI receiver accepting the note on / note off commands.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

naut



Then you can just use the attiny as a MIDI instrument manually sending the note on / note off commands over serial.



I forgot to mention that I don't really need the MIDI library on the attiny2313a, all I need is a way for buttons hooked up to the attiny to call functions located on the 328P. It does not matter to me what type of message the attiny sends to the 328P, be it midi or something else. I actually would prefer a way where the attiny would send a short string according to the button pushed and the 328 would read that string and call the appropriate function from the MIDI library.

---

btw, is it complicated to send messages over the serial port without using the Serial library?
I reckon that dedicated serial ShiftIn chips like the CD4021BE have a simplified mini version of the serial library?

mistergreen

You can send bytes via i2c.  There's a tut on the site on how to do that with attiny.

naut


You could use my ICSC (Inter-Chip Serial Communication) library that I'm working on:

https://sourceforge.net/projects/arduino-icsc/


Do you have the keyword file? It's not in the zip file.

majenko

No, I haven't written one yet.  I will do though, but it's low priority.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Go Up