Página 1 de 1
PIC18F4455

Enviado:
13 Ago 2008 10:48
por fabim
JENTI.RS
TO BRIGANDO COM O 18F4455, NUM PROJETINHO E agóra f**** o meio de campo aqui.
O SPI.
O SDO é multiplexado com o mesmo pino do RX da USART.
Só que minha Usart não vai receber dados, vai só mandar.
Será que tem uma forma de burlar isto, tipo eu ativar o USART apenas no TX, e o RX eu usar para o periférico da SPI ?
"não da pra fazer soft" tudo que o controlador vai supervisionar é muito rapido, não da pra ficar perdendo tempo."
FAbim

Enviado:
13 Ago 2008 10:50
por proex
Joga isso fora, use o 18F66J15.
Vc tra trabalhando com chip obsoleto e caro.

Enviado:
13 Ago 2008 14:27
por Sergio38br
boa tarde, vc esta usando a USB? se for usar a USB veja o 18F65J50 ou o 18F66J50 .Em qual linguagem vc vai programar?
Sergio

Enviado:
13 Ago 2008 14:44
por fabim
zóia. esse uControladores, "J". 66 sei lá oi que.
Infelizmente ainda esta impossivel encontrar no brasil, meu projeto por enquanto não vai usar a USB.
Peguei o 18F4455 por causa dos 48mhz.
Fabim

Enviado:
13 Ago 2008 14:53
por Sergio38br
qual linguagem que vai usar?
Sergio

Enviado:
13 Ago 2008 14:54
por fabim
PASCAL com um montão de tikim de ASM "para uns processos rapidos e chatos".
Fabim

Enviado:
13 Ago 2008 15:01
por Sergio38br
Pelo visto acho que vc vai ter de escrever a rotina de serial na mão, teoricamente vc pode ativar tanto o tx como rx juntos ou separadamente, cuidado com as interrupções. Esquece a rotina padrão do Mpascal da porta serial, ele ativa o rx e tx ao mesmo tempo.
Sergio

Enviado:
13 Ago 2008 15:18
por fabim
á sim, sobre ligar TX e RX no problem.
Eu posso usar o USART_init(31250);
Apenas para as config´s basicas de bud Rate etc.
Linha abaixo a esta eu faço a config de liga Apenas TX e desliga RX.
Aí vem o porque da minha pergunta, eu não estou achando o registrador que me permite ligar apenas o pino TX e desligar o RX.
Fabim

Enviado:
13 Ago 2008 15:23
por Sergio38br
para ajuda-lo,ai vai a parte da spi e uart serial em MikroB, facil portar para Mpascal
- Código: Selecionar todos
module H1_spi
CONST MASTER_OSC_DIV4 = 0 ' Master clock=Fosc/4
CONST MASTER_OSC_DIV16 = 1 ' Master clock=Fosc/16
CONST MASTER_OSC_DIV64 = 2 ' Master clock=Fosc/64
CONST MASTER_TMR2 = 3 ' Master clock source TMR2
CONST SLAVE_SS_ENABLE = 4 ' Master Slave select enabled
CONST SLAVE_SS_DIS = 5 ' Master Slave select disabled
CONST DATA_SAMPLE_MIDDLE = 0 ' Input data sampled in middle of interval
CONST DATA_SAMPLE_END = 128 ' Input data sampled at the end of interval
CONST CLK_IDLE_HIGH = 16 ' Clock idle high
CONST CLK_IDLE_LOW = 0 ' Clock idle low
CONST LOW_2_HIGH = 1 ' Data transmit on low to high edge
CONST HIGH_2_LOW = 0 ' Data transmit on high to low edge
implements
sub procedure H1_SPI_INIT_ADVANCED(dim master, data_sample, clock_idle, transmit_edge as byte)
TRISC.5 = 0 ' SDO is output
TRISC.3 = 0 ' SCK is output
TRISC.4 = 1 ' SDI is input
SSP1CON1 = 0 ' clear MSSP control register
SSP1CON1 = SSP1CON1 Or master ' master clock speed and master/slave modes
SSP1CON1 = SSP1CON1 Or clock_idle ' clock idle high or low
SSP1STAT = SSP1STAT Or data_sample ' data sampling in middle or end
If clock_idle <> 0 Then ' if clock idle is high (CPE=1) then
If transmit_edge = 0 Then ' if transmit edge is high_2_low then
SSP1STAT.6 = 1 ' (CKE=1) transmit occurs on transition from active to idle clock state
End If
Else ' if clock idle is low (CPE=0) then
If transmit_edge = 1 Then ' if tranmit edge is low_2_high then
SSP1STAT.6 = 1 ' (CKE=1) transmit occurs on transition from active to idle clock state
End If
End If
SSP1CON1.5 = 1 ' enables serial port and configures SCK, SDO, SDI as serial port pins
end sub
sub procedure H1_SPI_INIT
TRISC.5 = 0 ' SDO is output
TRISC.3 = 0 ' SCK is output
TRISC.4 = 1 ' SDI is input
SSP1CON1 = 0 ' clear MSSP control register
SSP1STAT = 64 ' transmit occurs on transition from active to idle clock state
SSP1CON1.5 = 1 ' enables serial port and configures SCK, SDO, SDI as serial port pins
end sub
sub procedure H1_SPI_WRITE(dim data as byte)
dim temp as byte volatile
SSP1BUF = data ' load data into SPI output buffer and send
While (SSP1STAT And 1) = 0 ' wait until 'Buffer-Full' flag is set
nop
Wend
temp = SSP1BUF ' dummy read receive buffer to clear BF flag
end sub
sub function H1_SPI_READ(dim buffer as byte) as byte
SSP1BUF = buffer ' load data into SPI output buffer and send
While (SSP1STAT And 1) = 0 ' wait until 'Buffer-Full' flag is set
nop
Wend
result = SSP1BUF ' read receive buffer and clear BF flag
end sub
end.
codigo uart
- Código: Selecionar todos
module usart_c67
implements
sub procedure USART_INIT
' compiler manages initial calculation of baud speed
' this is the setup for 9600 baud, Fosc=8MHz, which the compiler
' puts in the main program before the call to USART_INIT()
' SPBRG = 51
' TXSTA.BRGH = 1
TXSTA.5 = 1 ' transmit enable bit
RCSTA = 144 ' serial port enabled; continuous receive enabled
TRISC.7 = 1 ' RX pin is input
TRISC.6 = 0 ' TX pin is output
While Testbit(PIR1, 5) = 1 ' test RCIF...will hang here if set...no way to clear RCIF
Wend ' unless RX register is read
end sub
sub function USART_DATA_READY as byte
result = testbit(PIR1, 5) ' 0= RX register is empty; 1= byte in RX register
end sub
sub procedure USART_WRITE(dim data as byte)
While Testbit(TXSTA, 1) = 0 ' wait here until TX register is empty
nop
Wend
TXREG = data ' load TX register with new value and transmit
end sub
sub function USART_READ as byte
result = (RCSTA and %00000110)
If result <> 0 Then ' se ocorreu overrun ou framming erro
RCSTA.4 = 0 ' para recepcao continua
RCSTA.4 = 1 ' inicializa a recepcao continua
ax = 1
else
result = RCREG ' read value off top of RX register stack
End If ' overrun error is now cleared
end sub
sub procedure USART_WRITE_TEXT(dim byref uart_text as string[20])
dim i, data as byte
i = 0
data = uart_text[0] ' get first value
While data <> 0 ' look for end of string character ('0')
USART_WRITE(data) ' send character
inc(i)
data = uart_text[i] ' get next character
Wend ' loop to send new character
end sub
sub procedure USART_READ_TEXT(dim byref output, delimiter as string[20])
dim i, j, data, data2, lasti as byte
i = 0
j = 0
lasti = 0
data2 = delimiter[0]
While true
If Usart_Data_Ready <> 0 Then ' something has arrived
data = USART_Read ' read char
output[i] = data ' store char in data (delimiter is stored too)
If data = data2 Then ' does it match the sequence?
lasti = i - j ' indicate where output should end
inc(j) ' next letter in sequence
Else
j = 0 ' sequences do not match, reset counters
lasti = 0
End If
data2 = delimiter[j] ' get next delimiter
If data2 = 0 Then ' stop if the end of delimiter is reached
break
End If
inc(i)
If i > 20 Then ' too many chars received
lasti = 19
break
End If
End If
Wend
output[lasti] = 0 ' place the end of string before delimiter
end sub
end.
Olhe direito os registradores,
Abraços
Sergio

Enviado:
13 Ago 2008 15:31
por fabim
Hum, intão.
O que acontece aqui é o seguinte, quando vai usar como SPI, configura como SPI, quando é USART, configura como usart. aí num dá, aí num podi

.
Essa(s), rotinas simplesmente inicializam ou SPI ou USART, só <<.
Eu quero inicializar SPI, e USART, e não quero ficar trocando um liga outro depois desliga etc..
E como eu disse que não achei os registrados que permitem ligar TX ou RX separadamente intão, não tem mesmo..
FAbim

Enviado:
13 Ago 2008 15:32
por Sergio38br
OLHA , MANDEI TUDO ISSO E AGORA VEJO QUE OU VC ATIVA TUDO OU NADA. Da vontade de chorar...... o bit SPEN ativa toda a usart e o mesmo ocorre com o bit SSPEN...
Sergio

Enviado:
14 Ago 2008 14:55
por Sergio38br
Na farneel tem o PIC18F6520 com 2 UART, 1 MSSP com pinos diferenciados, mas com o unico incoviniente de rodar a apenas 40KHz maximo em modo HSPLL.
Sergio

Enviado:
14 Ago 2008 15:24
por Djalma Toledo Rodrigues
Sergio: 40 MHz e não apenas 40 kHz.

Enviado:
14 Ago 2008 15:56
por ze
um único ser que usa pascal em uCs num país de 3º mundo vai querer usar o chip de uma única maneira diferente uma única vez. porque será que a uxip não previu isso? rs. fica bravim não. sabia que temos um pelo menos 01 admirador [não muito] secreto? é... ainda existe gente de bom gosto. bem que podia ser uma admiradora. mai tá bão tamém.
abs e bfds!!!! (pra mim hoje é 6ª!!!!!!!) iuhuuuuu...