I'm very new to DMA and I was wondering if there's a way to update a variable from a function and send it through DMA? I currently have 2 teensy 4.1 hookup to each other through Serial 6. I have code below that allows both teensys to send and receive messages from each other. However, I'm trying to update one of the values, that gets sent over, through a function. Currently, the value is not updating and I was wondering if someone could give advice and suggestions on how to do this?
Code:
#include "DMASensor.h"
#include "DMAnChannel.h"
#include "DMAUART.h"
#include "Avatar_pinmap.h"
#include "Avatar_params.h"
DMASensor currh, currh_link;
DMAUART uart_link;
DMAnChannel dma_curr_s, dma_curr_r, dma_link_s, dma_link_r;
//value to be updated
volatile uint16_t curr=3;
//receive array
volatile uint16_t rec_link[3];
//send array
uint16_t snd_link[3];
//counters
int i = 0;
void setup() {
// put your setup code here, to run once:
rec_link[0] = 255;
snd_link[0] = 255;
currh.init(16,POS_TC);
currh.setAddr(snd_link+2);
currh_link.setAddr(rec_link+2);
uart_link.init(LINK_CH, link_uart);
dma_curr_r.init(0, &curr, currh.getAddr(), 0, enc_receive_tcd);
// Init DMA channels that handle sending/recieving position data over the device link bus
dma_link_s.init(8, snd_link, &(uart_link.ctrl->DATA), 0, link_send_tcd);
dma_link_r.init(9, &(uart_link.ctrl->DATA), rec_link, uart_link.dma_src_rx, link_receive_tcd);
//update curr in send array every 10khz
dma_curr_r.initPIT(2400);
//send message after curr update
dma_curr_r.linkCh(dma_link_s.ch);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
i=i+1;
curr=currupdate();
//snd_link[2] = curr;
Serial.println(" ");
Serial.print(rec_link[0]);
Serial.print(" ");
Serial.print(rec_link[1]);
Serial.print(" ");
Serial.print(rec_link[2]);
Serial.println("");
Serial.println(" ");
Serial.print(snd_link[0]);
Serial.print(" ");
Serial.print(snd_link[1]);
Serial.print(" ");
Serial.print(snd_link[2]);
Serial.println("");
}
uint16_t currupdate(){
float f = 1.15+i*0.1;
return (uint16_t) (f*1000);
}