Forum: Mikrocontroller und Digitale Elektronik USART in SPI mode Problem


von Christian L. (quadratqualle)


Lesenswert?

Hallo

ich versuch mit dem Atmega 644p den ENC28J60 Netzwerkcontroler über die 
USART1 Schnittstelle im SPI mode an zu steuern, was auf Grund des 
Boardlayouts (MyEthernet von Myavr) leider nicht anderes möglich ist. 
DAzu wollte ich erstmal nur die leds die man enc28j60 hängen ansteuern, 
was mir auch gelungen ist, aber komischerweise nur wen ich am Ende 
irgend ein Zeichen über die USART0 Schnittstelle an den PC sende(siehe 
Quelltext). Sobald ich das weglassen funktioniert es nicht mehr. Hat 
vielleicht irgendjemand eine Ahnung was ich falsch mache? Ich bin am 
Verzweifeln und bin für jede Hilfe sehr dankbar.
1
void enc28j60WriteOp(u08 op, u08 address, u08 data)
2
{
3
  ENC28J60_CONTROL_PORT &= ~(1<<ENC28J60_CONTROL_CS);
4
5
  // Wait for empty transmit buffer
6
  while ( !( UCSR1A & (1<<UDRE1)) );
7
  
8
  // issue write command
9
  UDR1 = op | (address & ADDR_MASK);
10
  // Wait for data to be received
11
  while ( !(UCSR1A & (1<<RXC1)) );
12
  // Get and return received data from buffer
13
  
14
  while ( !( UCSR1A & (1<<UDRE1)) );
15
  // write data
16
  UDR1 = data;
17
  // Wait for data to be received 
18
  while ( !(UCSR1A & (1<<RXC1)) );
19
20
  // sobald ich die 2 zeilen weg lasse funktioniert das ganz       
21
  //nicht mehr
22
  while (!(UCSR0A & 32));
23
  UDR0=0x05;
24
25
  ENC28J60_CONTROL_PORT |= (1<<ENC28J60_CONTROL_CS);
26
}

Hier noch die Initialisierung für die USART Verbindung im SPI mode:
1
void uart1_SPI(void)
2
{
3
4
DDRD  |= 1<<PD3 ; // mosi, sck, ss output
5
DDRD  &= ~(1<<PD2); // miso input
6
7
// Baud rate must be set to 0 prior to enabling the USART as SPI
8
// master, to ensure proper initialization of the XCK line.
9
UBRR1 = 0;
10
11
// Set XCK line to output, ie. set USART in master mode.
12
DDRD |= (1<<4); // Set XCK (BIT(4)) as an output
13
14
// Set USART to Master SPI mode.
15
UCSR1C = (1<<UMSEL11)|(1<<UMSEL10)|(0<<CPHA)|(0<<UCPOL1); 
16
17
// Enable RX and TX.
18
UCSR1B = (1 << RXEN1) | (1 << TXEN1); 
19
20
// Set baud rate. Must be set _after_ enabling the transmitter.
21
UBRR1 = 7; // Gives 1MHz 
22
}

von Claus A. (cand)


Lesenswert?

...und? Hast Du es zum rennen bekommen?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.