Tengo aproximadamente 1500 muestras almacenadas en la memoria de un ADC en una placa de desarrollo SL8051. Al compilar estos valores en un formulario CSV para enviar a través de UART, la transmisión se realiza aproximadamente 3/5 veces. Las otras veces está completamente confuso. La velocidad en baudios es la misma en ambos lados, y hemos comprobado que el UART enviado sea coherente con otros dispositivos receptores.
Código de adquisición
//Code to aqcuire from ADC
void main (void)
{
// unsigned char delay_count; // Used to implement a delay
// bit duty_direction = 0; // 0 = Decrease; 1 = Increase
// Disable watchdog timer
WDTCN = 0xde;
WDTCN = 0xad;
PORT_Init (); // Initialize crossbar and GPIO
OSCILLATOR_Init ();
PCA0_Init (); // Initialize PCA0
EMIF_Init (); // Storing ADC samples in SRAM
SFRPAGE = CONFIG_PAGE;
RAM_CS = 0; // assert SRAM chip select
UART0_Init (); // initialize UART0
Timer3_Init (SYSCLK/SAMP_RATE); // Init Timer3 for 100 ksps sample rate
ADC0_Init (); // configure ADC0 and ADC1 for differential measurement
EA = 1; // Globally enable interrupts
while(1)
{ // loop this logic for multiple samples
while(BB_GPIO_INPUT == 0);
SFRPAGE = TIMER01_PAGE;
TR0 = 1;
DMA0_Init (); // configure DMA to move NUM_SAMP samples
SFRPAGE = UART0_PAGE;
//printf ("Data Acquisition in progress...\n");
SFRPAGE = DMA0_PAGE; // Switch to DMA0 Page
while (!(DMA0CN & 0x40)); // Wait for DMA to obtain and move ADC samples
SFRPAGE = LEGACY_PAGE;
//printf ("Data Acquisition complete.\n");
SFRPAGE = TIMER01_PAGE;
TR0 = 0;
while(BB_GPIO_INPUT == 0);
SendData(); // Send data via the UART0
}
}
Código UART
//Code to print the data from DMA
void SendData (void)
{
unsigned int i;
char old_SFRPAGE = SFRPAGE;
SFRPAGE = UART0_PAGE;
read_ptr = XRAM_START_ADD; //pointer at beginning of data
for (i=0; i<NUM_SAMPLES; i++)
{
printf("%u",*read_ptr); // send data as unsigned integers
putchar(',');
read_ptr++;
}
printf("\n");
SFRPAGE = old_SFRPAGE;
}
Inic de UART
void UART0_Init (void)
{
char old_SFRPAGE = SFRPAGE;
SFRPAGE = UART0_PAGE; // Switch to UART0 page
SCON0 = 0x50; // SCON: mode 1, 8-bit UART, enable RX
SSTA0 = 0x10; // Timer 1 generates UART0 baud rate and
// UART0 baud rate divided by two disabled
SFRPAGE = TIMER01_PAGE; // Switch to timer 0/1 page
// TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TMOD &= 0x0F; // clear all T0 control bits
TMOD |= 0x20; // 8-bit auto-reload timer
TH1 = -(SYSCLK/BAUDRATE/16); // set timer 1 reload value for baudrate
TR1 = 1; // start timer1;
CKCON |= 0x10; // Timer1 uses SYSCLK as time base
PCON |= 0x80; // SMOD = 1
SFRPAGE = UART0_PAGE; // Switch to UART0 page
TI0 = 1; // indicate TX ready
SFRPAGE = old_SFRPAGE; // restore SFRPAGE
}