Uso un atmega32 y quiero usar el bus SPI. Tengo el controlador Adafruit 24 canales, 12 bits pwm led. Utilizo un búfer para establecer el pwm para un canal determinado.
¿La pregunta es cómo enviar todo el búfer a través de SPI?
Mi código:
/*
lat = ss
dat = mosi
clk = clock
oe = miso is not used because it is one directional
*/
uint16_t *pwmbuffer;
int numdriver = 1;
void tlc5947(uint8_t n){
pwmbuffer = (uint16_t *)calloc(2, 24 * n);
/* Set MOSI and SCK output, all others input */
DDRB = (1 << dat)|(1 << clk)|(1 << lat);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1 << SPE)|(1 << MSTR)|(1 << SPR0);
}
void write(){
/* Start transmission */
SPDR = pwmbuffer; // Here is the problem, I don't know how to do this
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}
void setPWM(uint8_t chan, uint16_t pwm){
if (pwm > 4095){
pwm = 4095;
}
if (chan > 24 * numdrivers){
return;
}
pwmbuffer[chan] = pwm;
}
int main(){
// This is not my real code but a simplified version of it
tlc5947(numdriver);
while(1){
setPWM(4, 2000);
write();
_delay_ms(5000);
setPWM(4, 100);
_delay_ms(5000);
}
}
Gracias de antemano