 |
 |
| View previous topic :: View next topic |
| Author |
Message |
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. |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Wed Mar 18, 2026 10:57 am |
|
|
If you look at page 713 of the datasheet for that controller, there *is* a "host start" for appropriate modes (host/receiver)
Without digging deep into how the DMA works, I would ask, did CCS forget something in terms of a C command? You may need some bit setting via overlaid struct to the I2CxCON0 register or inline ASM.
Point being: there IS a register that has a bit to issue a START condition.
I'm going to assume you have the datasheet already as well?
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|