Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: DMA_SPI.cpp
- Revision:
- 10:5b96211275d4
- Parent:
- 9:9ed9dffd602a
- Child:
- 11:366f1186c121
--- a/DMA_SPI.cpp Thu Mar 07 01:16:48 2019 +0000
+++ b/DMA_SPI.cpp Fri Mar 08 01:33:51 2019 +0000
@@ -201,29 +201,40 @@
SET_DMA1_CH3_CCR_PL_BITS(); //Priority Level = Highest
DMA1_Channel3->CNDTR = 12; //number of data to transfer from memory to the peripheral
- DMA1_Channel3->CPAR = (int32_t)&SPI1->DR; //Destination address = SPI data register
- DMA1_Channel3->CMAR = (int32_t)data_to_transmit; //Source address = data_to_transmit
+ DMA1_Channel3->CPAR = (uint32_t)&SPI1->DR; //Destination address = SPI data register
+ DMA1_Channel3->CMAR = (uint32_t)data_to_transmit; //Source address = data_to_transmit
//-----------------------------------------------Transmission------------------------------------------------
- // NVIC->ISER[0]|= (1u<<12); //Enable DMA1 channel 2 interrupt
- // NVIC->ISER[0]|= (1u<<13); //Enable DMA1 channel 3 interrupt
- // NVIC_EnableIRQ(DMA1_Channel2_IRQn);
- // NVIC_EnableIRQ(DMA1_Channel3_IRQn);
+ // NVIC->ISER[0] |= (1u<<12); //Enable DMA1 channel 2 interrupt
+ NVIC->ISER[0] |= (1u<<13); //Enable DMA1 channel 3 interrupt
+ // NVIC_EnableIRQ(DMA1_Channel2_IRQn);
+ NVIC_EnableIRQ(DMA1_Channel3_IRQn);
}
//Interrupt Handler for DMA1 Channel 2
-void DMA1_Channel2_IRQHandler(void) {
+extern "C" void DMA1_Channel2_IRQHandler(void) {
myled = 0; //Toggle LED off
CLEAR_DMA1_CH2_IFCR_GFLAG(); //Clear Global Interrupt flag
}
//Interrupt Handler for DMA1 Channel 3
-void DMA1_Channel3_IRQHandler(void) {
+extern "C" void DMA1_Channel3_IRQHandler(void) {
+ if(myled == 1) {
myled = 0;
- CLEAR_DMA1_CH3_IFCR_GFLAG(); //Clear Global Interrupt flag
+ }
+ else {
+ myled = 1;
+ }
+ if(DMA1->ISR&(1u<<9)) { //Check whteher data transmit transfer is complete
+ //Read data from the array that stores received data
+ for(int x = 0; x <= 12; x++) {
+ data_to_transmit[x] = x+1;
+ }
+ CLEAR_DMA1_CH3_IFCR_GFLAG(); //Clear global channel interrupt flag for channel 3
+ } //Clear Global Interrupt flag
}