EDIP128 und SPI

OP #4488877
Lesenswert?
• ▲
▼
Hallo Leute,

versuche gerade ein EDIP128 über SPI mittels eines ATmega328 mit 8MHz 
Quarz zu programmieren. Mein Code sieht momentan so aus:
1
/*
2
 * Display_Test.c
3
 *
4
 * Created: 06.02.2016 16:55:00
5
 *  Author: Admin
6
 */ 
7

8
#include <avr/io.h>
9
#include "EDIP128.h"
10
#include <string.h>
11
#include <stdio.h>
12
#include "global.h"
13
#include <util/delay.h>
14

15
void init_spi(void);
16

17
int main(void)
18
{
19
  char message[50];
20
  
21
  // Initialize SPI interface
22
  init_spi();
23
  
24
  sprintf(message, "ZC00Hello Word!\r");
25
  
26
  
27
    while(1)
28
    {
29
    transmit_EDIP128(message, strlen(message));
30
    _delay_ms(2000);
31
    }
32
}
33

34
// Function to initialize the microcontrollers SPI interface
35
void init_spi(void)
36
{
37
  // Set corresponding pins as outputs (SCK, MOSI, SS)
38
  DDRB = (1<<PB5) | (1<<PB3) | (1<<PB2);
39
  
40
  // Enable SPI, Master mode, fck/128
41
  SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0) | (1<<SPR1);
42
}
Und die Display-Funktionen:
1
/*
2
 * EDIP128.c
3
 *
4
 * Created: 06.02.2016 16:56:53
5
 *  Author: Admin
6
 */ 
7

8
#include <avr/io.h>
9
#include "global.h"
10
#include <util/delay.h>
11

12
void SendByte_EDIP128(unsigned char);
13

14
// Function to transmit data to the display
15
void transmit_EDIP128(char *buf, unsigned char len)
16
{
17
  unsigned char i, bcc;
18
  uint8_t ack;
19
  
20
  SendByte_EDIP128(0x11); // Send DC1
21
  bcc = 0x11;
22
  
23
  SendByte_EDIP128(len); // Send data length
24
  bcc = bcc + len;
25
  
26
  SendByte_EDIP128(0x1B); // Send ESC
27
  bcc = bcc + 0x1B;
28
  
29
  for(i = 0; i < len; i++) // Send buf
30
  {
31
    SendByte_EDIP128(buf[i]);
32
    bcc = bcc + buf[i];
33
  }
34
  
35
  SendByte_EDIP128(bcc); // Send checksum
36
  
37
  _delay_ms(100); // Wait until eDip is ready
38
  
39
  SendByte_EDIP128(0xFF); // Transmit dummy byte before next transmission
40
}
41

42
// Function to transmit a byte through SPI to the display
43
void SendByte_EDIP128(unsigned char byte)
44
{
45
  PORTB &= ~(1<<PB2); // Set chip select low
46
  
47
  SPDR = byte;
48
  
49
  // Wait for byte to be transmitted
50
  while(!(SPSR & (1<<SPIF)));
51
  
52
  PORTB |= (1<<PB2); // Set chip select high
53
  
54
  _delay_us(500);
55
}

Leider tut sich momentan garnichts auf dem Display :-(
OP #4491196
Lesenswert?
• ▲
▼
Ich habe das ganze jetzt mal auf I2C-Umgestrickt:
1
/*
2
 * DisplayTestI2C.c
3
 *
4
 * Created: 01.03.2016 19:30:26
5
 */ 
6

7
#include <avr/io.h>
8
#include "global.h"
9
#include "EDIP.h"
10
#include "I2C.h"
11
#include <util/delay.h>
12
#include <stdio.h>
13
#include <string.h>
14

15

16
int main(void)
17
{
18
  uint8_t cnt = 0;
19
  char msgBuf[20];
20
  
21
  // Initialize I2C-Interface
22
  init_I2C();
23
  
24
  // Transmit message to display
25
  sprintf(msgBuf, "Hello World!");
26
  LCD_Puts(msgBuf, strlen(msgBuf), 0x00, 0x00, 'L');
27
  
28
  while(1)
29
  {
30
    // Wait until next transmission
31
    _delay_ms(1000);
32
    sprintf(msgBuf, "Counter: %d", cnt);
33
    LCD_Puts(msgBuf, strlen(msgBuf), 0x00, 0x0E, 'L');
34
    cnt++;
35
  }
36
}
1
/*
2
 * EDIP.c
3
 *
4
 * Created: 01.03.2016 19:31:25
5
 */ 
6

7
#include <stdio.h>
8
#include "global.h"
9
#include "EDIP.h"
10
#include "I2C.h"
11
#include <util/delay.h>
12
#include <stdlib.h>
13

14

15
void LCD_Puts(char *buf, uint8_t len, uint8_t xpos, uint8_t ypos, uint8_t align)
16
{
17
  uint8_t cnt = 0;
18
  uint8_t bcc, ack;
19
  
20
  /********Transmit message*******/
21
  
22
  // Transmit I2C start-sign
23
  I2C_start();
24
  _delay_us(200);
25
  
26
  
27
  // Transmit I2C-Slave address
28
  I2C_slvaddr(0xDE);
29
  _delay_us(200);
30
  
31
  
32
  // Transmit DC1
33
  I2C_transbyte(0x11);
34
  bcc = 0x11;
35
  _delay_us(200);
36

37

38
  // Transmit data length
39
  len += 6; // + ESC + Z + Align+ xpos + ypos + \0
40
  I2C_transbyte(len);
41
  bcc += len;
42
  _delay_us(200);
43
  
44
  
45
  // Transmit ESC
46
  I2C_transbyte(0x1B);
47
  bcc += 0x1B;
48
  _delay_us(200);
49
  
50
  // Transmit text command
51
  I2C_transbyte('Z');
52
  bcc += 'Z';
53
  _delay_us(200);  
54
  
55
  // Transmit alignment of text
56
  I2C_transbyte(align);
57
  bcc += align;
58
  _delay_us(200);
59
  
60
  // Transmit x position
61
  I2C_transbyte(xpos);
62
  bcc += xpos;
63
  _delay_us(200);
64
  
65
  // Transmit y position
66
  I2C_transbyte(ypos);
67
  bcc += ypos;
68
  _delay_us(200);
69
  
70
  // Transmit data via I2C-Interface
71
  for(cnt = 0; cnt < (len - 5); cnt++)
72
  {
73
    I2C_transbyte(buf[cnt]);
74
    bcc += buf[cnt];
75
    _delay_us(200);
76
  }
77
  
78
  
79
  // Transmit bcc
80
  I2C_transbyte(bcc);
81
  _delay_us(200);
82
  
83
  
84
  // Transmit I2C stop-sign
85
  I2C_stop();
86
  _delay_us(200);
87
  
88
  
89
  /********Read acknowledge*******/
90
    
91
  // Transmit I2C start-sign
92
  I2C_start();
93
  _delay_us(200);
94
    
95
    
96
  // Transmit I2C-Slave address
97
  I2C_slvaddr(0xDF);
98
  _delay_us(200);
99
  
100
  
101
  // Read acknowledge
102
  ack = I2C_rec();
103
  _delay_us(200);
104
  
105

106
  // Transmit I2C stop-sign
107
  I2C_stop();
108
  _delay_us(200);
109
}

Also "Hello World!" und "Counter: 0" zeigt er an, aber danach ist 
schicht im Schacht. Auf dem LA sehe ich, dass das zum "Counter: 0" 
gehörige ACK noch empfangen wird, aber dann bleibt die SDA-Leitung low 
(Pull-Ups sind dran ;-) )

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren