Pages: [1]   Go Down
Author Topic: call a function from another chip?  (Read 650 times)
0 Members and 1 Guest are viewing this topic.
geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
 
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 649
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 10
Posts: 649
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 196
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

geo. area called Italia
Offline Offline
Full Member
***
Karma: 0
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I haven't written one yet.  I will do though, but it's low priority.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Pages: [1]   Go Up
Jump to: