Go Down

Topic: attiny 85, any pointers?/ (Read 22566 times) previous topic - next topic

winner10920

Srry I meant to post it last post, my phone doesn't seem to want to post it right now, ill tyr again tomorrow on an actual computer

skootles

Thanks, can't wait to get this working.

winner10920

srry for the delay

skootles

No problem. Could I bother you for the receiver code as well?

winner10920

heres some code that recieves a message and i think replies as ewell as readoff to an lcd, but it is for an uno and doesnt use the attiny85 spi

Shrugs

I'm not quite sure what I'm not doing correctly. Hopefully you can help me out. My pin connections:

ATtiny84        -> Nrf24L01+
MISO (PA6) -> MISO
MOSI (PA5) -> MOSI
SCK   (PA4) -> SCK
CSN   (PA3) -> CSN
CE     (PA2) -> CE

The code uploads to the ATtiny84 perfectly well, and seems to be working.

When I run the uno code you provided, though, it fails to detect any data. Here are the connections:

UNO            -> Nrf24L01+
D9               -> CE
D10             -> CSN
D11 (MOSI) -> MOSI
D12 (MISO) -> MISO
D13 (SCK)   -> SCK  

And here is the stripped down code:
Code: [Select]

ATTinyMirf.ino

#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>
#include "SoftwareSerial.h"



byte data[32] = {
 'T','T','W','I','R','E','L','E','S','S','Q','Q','Q','Q','Q','Q',
 'Q','Q','R','J','F','E','D','O','R','Q','Q','Q','Q','Q','Q','Q'
};

SoftwareSerial mySerial(9,10);

void setup(){
 mySerial.begin(9600);
 mySerial.write("ATTINY - Setup\n");
 
 // pinMode(3,0);
 pinMode(0, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 // digitalWrite(3,1);
 delay(1000);
 
 Mirf.cePin = 2; //attiny
 Mirf.csnPin = 3; //attiny
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();

 Mirf.setRADDR((byte *)"sendr");
 Mirf.payload = 32;
 Mirf.channel = 8;
 Mirf.setTADDR((byte *)"reply");
 Mirf.send(data);
delay(3000);
mySerial.write("ATTINY - End Setup\n");

}

void loop(){

 delay(1000);
 digitalWrite(0, HIGH);
 mySerial.write("ATTINY - Sending... \n");

 Mirf.send(data);
 digitalWrite(0, LOW);
 delay(100);

 
}



and for the UNO:

Code: [Select]

UnoMIRF.ino

//mirf recieve and replay
/*
PIN ||arduino || mirf
GND ||  GND   ||  1
VCC ||  5V    ||  2
CE  ||     9  ||  3
CSN ||     10 ||  4
SCK ||     13 ||  5
MOSI||     11 ||  6
MISO||     12 ||  7
IRQ ||  NA    ||  8
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
byte data[32]; //size of payload
void setup(){
 Serial.begin(9600);
 //begin nrf24ll01
 Mirf.cePin = 9; //uno
 Mirf.csnPin = 10; //uno
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();

 Mirf.setRADDR((byte *)"reply");
 Mirf.setTADDR((byte *)"sendr");
 Mirf.payload = 32;
 Mirf.channel = 8;
 Mirf.config();
 Serial.println("Setup finished");
}
void loop(){
 // Serial.print(".");

 if(Mirf.dataReady()){
   Mirf.getData(data);


   delay(50);
   for (int i = 0; i < 32; ++i)
   {
     Serial.print(data[i]);
     Serial.print(",");
   }
   Serial.println();
 }

}




I'm pretty sure the chips themselves work; the RF24 library was able to get the status register of the transceivers, so it must be a problem with the ATtiny and/or Uno code

Thank you again

skootles

#51
Dec 18, 2012, 06:33 am Last Edit: Dec 18, 2012, 06:48 pm by skootles Reason: 1
I'm also having an issue getting this working on an ATtiny84. I've had success with the ATtiny85 however. Perhaps there's an error in the library?

Edit: Oh, and of course thanks winner10920 for your code.

Shrugs

It works well on the 85? I think I'll go ahead and get some of those, then. I assume I'll have to change the pin assignments in the library? From PORTA to PORTB, that is.

winner10920

In the library I included a define for the 84, perhaps depending on your method of enabling attiny use on arduino because I based it on the third party source that I used, I believe there are 2-3 different ones, perhaps that's the fault, ill try on an 84 when I get the chance, tho I think someone else said it worked on an 84

Shrugs

Oh ya, I forgot to specify that I had to manually comment out the ATTiny "if defined" part in SPI85 because it wasn't recognizing the core as an __AVR_ATtinyX4__. That's probably the problem. So would I use a different ATTiny core or what?

Yea, somebody above got it working on an 84.

winner10920

Just change the core name to whichever yours is, youll find the name within the attiny core itself, I found it I think by pin definitions, then it will automatically recognize it

Shrugs

Right, right. Wait, since I manually commented it out and forced the pin definitions to be for the 84, wouldn't it work already?
I changed
Code: [Select]

#if defined( __AVR_ATtinyX4__ )
const static uint8_t SS   = PA7;
const static uint8_t MOSI = PA5;
const static uint8_t MISO = PA6;
const static uint8_t SCK  = PA4;
#endif

To:
Code: [Select]

//#if defined( __AVR_ATtinyX4__ )
const static uint8_t SS   = PA7;
const static uint8_t MOSI = PA5;
const static uint8_t MISO = PA6;
const static uint8_t SCK  = PA4;
//#endif

So the pins are definitely correct, I think.

winner10920

Does anything change when you force the definitions?

Shrugs

It stops giving me the "SS/MOSI/MISO/SCK is undefined in this context" or whatever messages and compiles perfectly. I had done that previously, so now I don't think that it's related to my problems now. Thanks for helping, by the way.

winner10920

Np, let me know if u figure it out, feels good to know something I made works for other people too lol

Go Up