PeterStr
Joined: 21 Jan 2026 Posts: 3
|
| More PIC18 DMA woes |
Posted: Mon Mar 09, 2026 7:55 pm |
|
|
Trying to wrap my head around the way to set up the PIC18's (PIC18F05Q20, namely) DMA to work with the I2C peripheral to handle refreshing of an LCD screen buffer in the background. However, can't figure out the proper way to set it all up. I wrote a simple test case to see if I can get a single short packet sent over the I2C bus, but nothing happens. I understand that somehow an initial trigger needs to be fired in order to start DMA transfer. I was intending to use i2c_start() for such purpose, which would assert the first IF flag to get things going. Turns out, the PIC18's I2C peripheral does not support any I2C functions other than i2c_transfer()
Here's the code for the test case:
| Code: |
#include <main.h>
void main()
{
int8 TestStr[] = {0x7A, 0x60, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
setup_dma(1, DMA_TRIGGER_I2C1TX, DMA_TRIGGER_NONE);
dma_start(1, (DMA_SOURCE_ADDR_IS_SFR_GPR | DMA_INC_SOURCE_ADDR|DMA_DEST_ADDR_UNCHANGED | DMA_ONE_SHOT_FROM_SOURCE_COUNT | DMA_HW_TRIGGER_STARTS_XFER), &I2C1TXB, TestStr, 1, 8);
dma_go(1);
while(TRUE)
{
//TODO: User Code
}
}
|
and this is the header:
| Code: |
#include <18F05Q20.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS_8MHZ //Crystal osc <= 8MHz
#FUSES NOBROWNOUT //No brownout reset
#FUSES BBSIZ128 //128 words Boot block size
#pin_select SDA1=PIN_C1
#pin_select SCL1=PIN_C0
#use delay(internal=8MHz)
#use i2c(Master,Fast,sda=PIN_C1,scl=PIN_C0)
#byte I2C1TXB = 0x01F0
|
How do I get this to work? Any help will be greatly appreciated.
Peter. |
|