mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 11:54:30 +03:00
fixed i2c (internal pullup + right scan method)
This commit is contained in:
@@ -27,17 +27,17 @@
|
||||
#define DMATXCCR (DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE | DMA_CCR_TEIE)
|
||||
|
||||
volatile int u3txrdy = 1, u3rxrdy = 0; // transmission done, next line received
|
||||
static int bufovr = 0, wasbufovr = 0; // Rx buffer overflow or error flag -> delete next line
|
||||
static int rbufno = 0, tbufno = 0; // current buf number
|
||||
static char rbuf[2][UARTBUFSZ], tbuf[2][UARTBUFSZ]; // receive & transmit buffers
|
||||
static int rxlen[2] = {0}, txlen[2] = {0};
|
||||
static volatile int bufovr = 0, wasbufovr = 0; // Rx buffer overflow or error flag -> delete next line
|
||||
static volatile int rbufno = 0, tbufno = 0; // current buf number
|
||||
static volatile char rbuf[2][UARTBUFSZ], tbuf[2][UARTBUFSZ]; // receive & transmit buffers
|
||||
static volatile int rxlen[2] = {0}, txlen[2] = {0};
|
||||
|
||||
char *usart3_getline(int *wasbo){
|
||||
if(wasbo) *wasbo = wasbufovr;
|
||||
wasbufovr = 0;
|
||||
if(!u3rxrdy) return NULL;
|
||||
u3rxrdy = 0; // clear ready flag
|
||||
return rbuf[!rbufno]; // current buffer is in filling stage, return old - filled - buffer
|
||||
return (char*)rbuf[!rbufno]; // current buffer is in filling stage, return old - filled - buffer
|
||||
}
|
||||
|
||||
#define USART_BRR(speed) ((64000000 + speed/2) / speed)
|
||||
@@ -84,7 +84,7 @@ int usart3_send(const char *str, int len){
|
||||
int rest = UARTBUFSZ - txlen[tbufno];
|
||||
if(rest == 0 && !u3txrdy) return 0; // buffer is full while transmission in process
|
||||
if(len < rest) rest = len;
|
||||
mymemcpy(tbuf[tbufno] + txlen[tbufno], str, rest);
|
||||
mymemcpy((char*)(tbuf[tbufno] + txlen[tbufno]), str, rest);
|
||||
txlen[tbufno] += rest;
|
||||
if(!u3txrdy) return rest;
|
||||
if(txlen[tbufno] == UARTBUFSZ) usart3_sendbuf();
|
||||
@@ -92,7 +92,7 @@ int usart3_send(const char *str, int len){
|
||||
len -= rest;
|
||||
// now fill another - empty - buffer
|
||||
if(len > UARTBUFSZ) len = UARTBUFSZ;
|
||||
mymemcpy(tbuf[tbufno], str + rest, len);
|
||||
mymemcpy((char*)tbuf[tbufno], str + rest, len);
|
||||
txlen[tbufno] = len;
|
||||
return rest + len;
|
||||
}
|
||||
@@ -157,7 +157,6 @@ void dma1_channel2_3_isr(){
|
||||
uint32_t isr = DMA1->ISR;
|
||||
if(isr & (DMA_ISR_TCIF2 | DMA_ISR_TEIF2)){ // transfer complete or error
|
||||
u3txrdy = 1;
|
||||
//DMA1_Channel2->CCR = DMATXCCR;
|
||||
}
|
||||
if(isr & (DMA_ISR_TCIF3 | DMA_ISR_TEIF3)){ // receive complete or error -> buffer overflow
|
||||
if(rbuf[rbufno][UARTBUFSZ-1] != '\n'){ // last symbol is not a newline
|
||||
|
||||
Reference in New Issue
Block a user