Ist das lustig?

War nicht beabsichtigt...
Aber schön, wenn ich dich unterhalten konnte

Aber zurueck zum Thema:
Mir ging es wirklich eher darum, ob jemand von euch schon so etwas gemacht hat und wenn ja mit welchen Mitteln.
Hab mich da vieleicht, sprich bestimmt, etwas doof ausgedrueckt.

Es ging mir alse eher um allgemeine Tipps, an denen ich vieleicht erkenne, wo mein Denkfehler liegt.

Aber zurueck zur Hardware:
Es handelt sich dabei um die Programmierung eines ATmega128, den ich via SPI dazu ueberreden will sowohl Daten zu senden, als auch zu empfangen.
Zum Uebertragen und Empfangen nutze ich das nRF2401 EVBOARD von Nordic Semiconductors ( http://www.nvlsi.no/ ).
Als Programmierumgebung nutze ich IAR Embedded Workbench IDE und IARs MakeApp hat mir das Grundgeruest mit allen möglichen voreinstellungen und Makros geliefert.
Da weis ich aber, dass es da noch Probleme gibt und da ich eher Anfänger in der HW-Programmierung bin, sehe ich sie oftmals schlichtweg nicht!

Hier mal etwas Code:
Code:
void SendAndWait( U8 data )
{

  if ( MA_OK != MA_PutChar_SPI( data ) );// cout<<"DAMN!";
  //else cout<<"OK! ";
  while( MA_OK!=MA_TestChar_SPI() );
  //cout<<"LOOP DONE!";  
}

void Init_Ism( int send )
{
  PORTB |= 0x20;  //CS = 1
  wait(200);     //wait
  
  //char Init_ShockBurst_DATA2W[8]=       how much bits do you send? see send-function!
  SendAndWait( 0x20 );                  //I decided to leave this value unmodified, but write a function, that send only four bytes - 32 bits!

  //char Init_ShockBurst_DATA1W[8]=
  SendAndWait( 0x20 );

  //char Init_ShockBurst_ADDR2[40]=       Adress Channel 2
  SendAndWait( 0xBB); SendAndWait( 0xBB); SendAndWait( 0xBB);
  SendAndWait( 0xBB); SendAndWait( 0xBB);
  
  //char Init_ShockBurst_ADDR1[40]=       Adress Channel 1
  SendAndWait( 0xBB); SendAndWait( 0xBB); SendAndWait( 0xBB);
  SendAndWait( 0xBB); SendAndWait( 0xBB);

  //char Init_ShockBurst_ADDRW[6]=
  //{0,0,1,0,0,0};
  //char Init_ShockBurst_CRC[2]=
  //{0,1};
  SendAndWait( 0xA1);//84                        Binary Add ADDRW & CRC

  //char Init_ShockBurst_RFPROG[16]=
  //{0,1,0,0,1,1,1,1,0,0,0,0,0,1,0,0};    divide into 2 Byte á 8 bit and send away
  SendAndWait( 0x4F);
  
  if ( send == 1 ) SendAndWait( 0x04);        //to receive, switch last bit to 1, 0 means transmit
  if ( send == 0 ) SendAndWait( 0x05);
  
  PORTB &= ~(0x20);   //set CS = 0
  wait(200);          //wait
}

void sendMsg( char *string )
{
  char part[4] = { ' ', ' ', ' ', ' ' };
  int length;
  int i;
  
  //Message to UART0
  cout<<"Sending Message...\n";
  
  length = strlen( string );
  for( i = 0; i<length; i++ )
  {
    if ( i == 0 )
      part[0] = string[i];
    if ( (i % 4) == 1 && i != 0 )
      part[1] = string[i];
    if ( (i % 4) == 2 && i != 0 )
      part[2] = string[i];
    if ( (i % 4) == 3 && i != 0 )
      part[3] = string[i];
    if ( (i % 4) == 0 && i != 0 )
    {
      sendMsgPart( part );
      
      part[0] = ' '; part[1] = ' ';
      part[2] = ' '; part[3] = ' ';
      
      part[0] = string[i];
    }    
  }
  
  sendMsgPart( part );
  
  //Show the transmitted message
  cout<<string<<"\n";
}

void sendMsgPart( char *string )
{
  PORTB |= 0x10;    //CE = 1
  wait(200);  

  //ShockBurst_ADDR1[40]=
  //{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  //0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  //1,1,1,0,0,1,1,1};        prepare the Addess Channel to send some information
  SendAndWait(0xBB);
  SendAndWait(0xBB);
  SendAndWait(0xBB);
  SendAndWait(0xBB);
  SendAndWait(0xBB);

  //lähetettävä viesti      Send your information here
  SendAndWait( string[0] );
  SendAndWait( string[1] );
  SendAndWait( string[2] );
  SendAndWait( string[3] );  
  
  //cout<<string;
  
  PORTB &= ~(0x10);   //CE = 0
  wait(200);
}

void wait( unsigned long tmr_ms )
{
  __tmr_ms=0; //global variable
  MA_Start_TMR( 0, 1 );  //parameters: channel & reset on start
  while(__tmr_ms !=tmr_ms); //wait
  MA_Stop_TMR( 0 ); //no comment
}
SendAndWait ist eine SPI-Funktion und macht genau das, was der Name sagt.
Wie man später in der Init_Ism-Funktion sieht, sendet sie die Infomationen an die Funkstrecke.
Diese Funktion, Init_Ism, funktioniert auch tadellos bei der Initialisierung zum senden, rein theoretisch, laut der Doku die man zum nRF2401 findet, sollte es alles bis auf das letzte Bit so bleiben, wenn man emfangen will, aber ich glaube, dass genau hier was nicht hinhaut.
Ich denke, die anderen Funktionen muss ich nicht erklären.
So ich hoffe, dass hilft jetzt weiter!

Falls nicht: Machts wie Andun - schreibts!

Vielen Dank

BGMF




edit:

Da fällt mir noch ein:
Code:
char *getString( void )
{
  char *string;
  char singleChar;
  int i = 0;
  
  while( 1 )
  {
    singleChar = MA_GetChar_SPI();
    
    if ( singleChar == 0 )
      break;
    
    string[i] = singleChar;
    i++;    
  }
  
  cout<<string;
  return string;  
}
Meine "Vom-SPI-Empfangs"-Funktion...
Die is doch bestimmt Gruetze, oder?
Kritiken und Anmerkungen ausdruecklich Erwuenscht!


edit^2:

Man bin ich ne Pfeife (darauf möchte ich keinen Kommentar hören, bitte!)
Hier noch meine Main-Funktion:
Code:
void main( void ) 
{
    char *string;


    MA_Init_CPU();

    MA_Init_SPI();
    MA_InitCh0_USART();
    
    MA_Reset_SPI();

    MA_Init_IO();
    MA_Init_TMR();
    
    __enable_interrupt();
    
    DDRB |= 0x30;   //Prepare the DDRB for input of the CS and CE signal
    wait(100);      //wait, maybe not neccessary
       
    //Init_Ism( 1 );
    //sendMsg( "This is a teststring!" );

    Init_Ism( 0 );
    
    PORTB |= 0x10;    //CE = 1
    wait(200);
        
    while( 1 )
    {
      if ( PINB & 0x40 )
      {
        //while ( cout<<MA_GetChar_SPI() );
        //break;
        string = getString();
        if ( string != "" ) break;
      }
    }
    
    PORTB &= ~(0x10);   //CE = 0
    wait(200);

} /* main */
Ne kurze Erklärung ist hier noch fällig, glaube ich:
CS, das is in der Init-Fkt zu finden, sagt dem nRF2401, dass jetzt Konfigurationsdaten kommen, die also nicht weggesendet werden muessen.
CE bedeutet, jetzt ist Zeit fuer Daten, sowohl beim senden, als auch beim Empfangen.
Die Aktion mit (PINB & 0x40) sagt aus, das auf ein "Startsignal" von der Funkstrecke gewartet wird, dort wird ein Bit gesetzt, nennt sich DR1, welches ich vom 5ten Pin am Port B ablesen will.
Ich hatte an dieser Stelle vorher nur (PORTB & 0x40) zu stehen, das hat nicht geklappt, jetzt springt er da rein - also scheint die Konfiguration doch zu stimmen.
Bleibt die Frage: Was empfängt er? Empfängt er ueberhaupt? Wie komme ich an die Daten ran... Puh...