| Author |
Message |
|
|
Posted: May 11, 2012 - 02:43 PM |
|

Joined: Jul 14, 2008
Posts: 20
|
|
Hi,
I want to sample a signal with 100khz with an UC3A1512. The signal comes from an ADC that is read by SPI (20Mhz). I "generate" the 100khz sampling by a timer that calls an ISR with 100khz. At the beginning of the ISR I want to start the ADC readout by DMA and the start my computation (just a very few additions). When I try to send data "normally" in the ISR, everything works fine. But when I try to do this by DMA I can't see anything on the Scope. Do you have an Idea how to solve this?
Code:
static const pdca_channel_options_t PDCA_OPTIONS_RX =
{
.addr = (void *)&SPI_RX_Buffer, // memory address
.pid = AVR32_PDCA_PID_SPI0_RX, // select peripheral, SPI1
.size = 2,//sizeof(SPI_RX_Buffer), // transfer counter
.r_addr = NULL, // next memory address
.r_size = 0, // next transfer counter
//16 bits
.transfer_size = PDCA_TRANSFER_SIZE_HALF_WORD // select size of the transfer
};
static const pdca_channel_options_t PDCA_OPTIONS_TX =
{
.addr = (void *)&SPI_TX_Buffer, // memory address
.pid = AVR32_PDCA_PID_SPI0_TX, // select peripheral. , SPI1
.size = 1,//sizeof(SPI_TX_Buffer), // transfer counter
.r_addr = NULL, // next memory address
.r_size = 0, // next transfer counter
//16 bits
.transfer_size = PDCA_TRANSFER_SIZE_HALF_WORD // select size of the transfer
};
pdca_enable(SPI_PDCA_CHANNEL_TX);
pdca_enable(SPI_PDCA_CHANNEL_RX);
pdca_load_channel(SPI_PDCA_CHANNEL_TX,(void *)&SPI_TX_Buffer, 2);
pdca_load_channel(SPI_PDCA_CHANNEL_RX,(void *)&SPI_RX_Buffer, 2);
__attribute__((__interrupt__)) static void tc_irq(void)
{
// Clear interrupt flag
tc_read_sr(&AVR32_TC, 0);
pdca_load_channel(SPI_PDCA_CHANNEL_TX,(void *)&SPI_TX_Buffer, 2);
//do some stuff
}
|
|
|
| |
|
|
|
|
|
Posted: May 11, 2012 - 03:21 PM |
|

Joined: Aug 25, 2011
Posts: 394
Location: Europe
|
|
| You don’t actually use PDCA_OPTIONS_TX and PDCA_OPTIONS_RX in the code snippet you posted. Where do you configure the PDCA to use the SPI module and to use half words? I miss a pdca_init_channel in your code. |
|
|
| |
|
|
|
|
|
Posted: May 12, 2012 - 12:22 AM |
|

Joined: Aug 19, 2003
Posts: 403
Location: Australia
|
|
| Where or when is a chip-select done on the SPI module ? |
|
|
| |
|
|
|
|
|
Posted: May 12, 2012 - 03:41 PM |
|

Joined: Jul 14, 2008
Posts: 20
|
|
Sorry,
I forgot to copy the
Code:
static const gpio_map_t SPI_GPIO_MAP =
{
{AVR32_SPI0_SCK_0_0_PIN , AVR32_SPI0_SCK_0_0_FUNCTION }, // SPI Clock.
{AVR32_SPI0_MISO_0_0_PIN, AVR32_SPI0_MISO_0_0_FUNCTION }, // MISO.
{AVR32_SPI0_MOSI_0_0_PIN , AVR32_SPI0_MOSI_0_0_FUNCTION }, // MOSI.
{AVR32_SPI0_NPCS_0_0_PIN , AVR32_SPI0_NPCS_0_0_FUNCTION }, //Chip select
};
pdca_init_channel(0, &PDCA_OPTIONS_RX);
pdca_init_channel(1, &PDCA_OPTIONS_TX);
from my code, so I set the spi pins and init the channels...
Best regards
Christoph |
|
|
| |
|
|
|
|
|
Posted: May 12, 2012 - 10:27 PM |
|

Joined: Aug 19, 2003
Posts: 403
Location: Australia
|
|
Do you do an spi_selectChip(,) ?
What is the ADC chip ?, does it use the CS line to control its' operation ? |
|
|
| |
|
|
|
|
|
Posted: May 13, 2012 - 06:31 AM |
|

Joined: Jul 14, 2008
Posts: 20
|
|
Hi,
yes, the ADC needs a chip-select. But however I don't see the at least clock on the oscilloscope, so I think there is no SPI communication from the AVR32 to the ADC... |
|
|
| |
|
|
|
|
|
Posted: May 13, 2012 - 07:29 AM |
|

Joined: Aug 19, 2003
Posts: 403
Location: Australia
|
|
What is your configuration for the SPI module and the channel(s) ?
You need to do at least one spi_selectChip(,) before the spi module will send anything.
What is the part number of the ADC chip ?
If the ADC chip needs CS then you probably need to activate it before you start the PDC transfer. |
|
|
| |
|
|
|
|
|
Posted: May 13, 2012 - 01:25 PM |
|

Joined: Jul 14, 2008
Posts: 20
|
|
Hi,
ok, after a
Code:
spi_selectChip(&AVR32_SPI0, 0);
everything works fine. But is there a way to deaktivate the chip after a reading without polling or an ISR? |
|
|
| |
|
|
|
|
|
Posted: May 13, 2012 - 07:54 PM |
|

Joined: Aug 19, 2003
Posts: 403
Location: Australia
|
|
Figure 23-6 (Master Mode Flow Diagram) and 23.7.3.7 (Peripheral Deselection) in the datasheet.
Try CSAAT = 0 in the CSR or if you use the ASF set .stay_act= 0; in your spi_options_t for channel 0.
Deselecting the CS and then selecting it before you start the PDC transfer might work. I don't know how your external ADC operates. |
|
|
| |
|
|
|
|
|
Posted: May 14, 2012 - 05:29 AM |
|

Joined: Jul 14, 2008
Posts: 20
|
|
Absolutely perfect! Everything works fine!!! But one last question (cause the ADC is currently not connected - still waiting for the PCB): I have a one channel ADC, so I don't have to send a channel selection or something like this. The result is issued after the first 3 clock cycles, so I send only 0 to the ADC. Since SPI is normaly operates with a shift register - do I have "something special" to get the RX data or is it in the RX Buffer after the transmission?
Thanks and best regards
Christoph |
|
|
| |
|
|
|
|
|
Posted: May 14, 2012 - 07:25 AM |
|

Joined: Aug 19, 2003
Posts: 403
Location: Australia
|
|
|
Quote:
do I have "something special" to get the RX data or is it in the RX Buffer after the transmission?
yes.,
In your tc_irq() the
Code:
pdca_load_channel(SPI_PDCA_CHANNEL_TX,(void *)&SPI_TX_Buffer, 2);
will transmit your command/data/whatever and this generates the clock which is used to receive data from your mysterious ADC.
You also need a
Code:
pdca_load_channel(SPI_PDCA_CHANNEL_RX,(void *)&SPI_RX_Buffer, 2);
in tc_irq() to put the received data into your buffer. |
|
|
| |
|
|
|
|
|